I have the following:
System.Globalization.CultureInfo c = new System.Globalization.CultureInfo("en-GB"); var a = c.DisplayName; var b = c.EnglishName; var d = c.LCID; var e = c.Name; var f = c.NativeName; var g = c.TextInfo; var h = c.ThreeLetterISOLanguageName; var i = c.ThreeLetterWindowsLanguageName; var j = c.TwoLetterISOLanguageName;
None of this gives me the country code, e.g. GB
.
Is there a way to get it without string splitting?
If you need the country name in the native language of that country, you can use CultureInfo. CurrentCulture. NativeName instead. If you need the two letter country code, you can use CultureInfo.CurrentCulture.Name, which returns "languageCode-countryCode" (e.g. en-CA).
The CultureInfo class provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. This class also provides access to culture-specific instances of the DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo objects.
The CultureInfo. CurrentCulture property is a per-thread setting; that is, each thread can have its own culture. You get the culture of the current thread by retrieving the value of the CultureInfo. CurrentCulture property, as the following example illustrates. C# Copy.
var c = new CultureInfo("en-GB"); var r = new RegionInfo(c.LCID); string name = r.Name;
Most probably you need to use r.TwoLetterISORegionName
property.
string regionName = r.TwoLetterISORegionName;
System.Globalization.CultureInfo c = new System.Globalization.CultureInfo("en-GB"); var ri = new RegionInfo(c.Name); string countryName = ri.DisplayName;
That will give you:
"United Kingdom"
For Two Letter Use:
string countryAbbrivation = ri.TwoLetterISORegionName;
That will give you "GB"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With