Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get country name

I used the code below to get the list of culture type, is there a way on how to get just the country name?

Thank you

static void Main(string[] args)
{
    StringBuilder sb = new StringBuilder();
    foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
    {
        sb.Append(ci.DisplayName);
        sb.AppendLine();
    }
    Console.WriteLine(sb.ToString());
    Console.ReadLine();
}

Sample Output:

Spanish (Puerto Rico)

Spanish (United States)

like image 754
xscape Avatar asked Sep 07 '10 04:09

xscape


People also ask

How can I get country name in locale?

Locale l = new Locale("", "NL"); String country = l. getDisplayCountry();

How do you create a country code?

Goto SAP IMG -> SAP NetWeaver -> General Settings -> Set Countries -> Define Countries & Insert Regions. There you can do country specific setting also.


1 Answers

You can use the Name property of the CultureInfo to construct a RegionInfo. You can then use the DisplayName property. Try:

foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
    var ri = new RegionInfo(ci.Name);
    Console.WriteLine(ri.DisplayName);
}
like image 55
Eric MSFT Avatar answered Oct 06 '22 06:10

Eric MSFT