regioninfo

Get a country's continent in C#

北战南征 提交于 2020-06-27 08:07:14
问题 Is there a way to find a country's continent in C#, using the RegionInfo class or any other way? For example, you give the country name "Denmark" and it returns "Europe". 回答1: You can store a hash table. The entries will have as key the country name and as value the continent name. Just generate this table from some public database and once you have it you can simply query it. It's also pretty fast. http://www.geonames.org/countries/ You can get from there a database (there is an option to

Get a country's continent in C#

走远了吗. 提交于 2020-06-27 08:06:10
问题 Is there a way to find a country's continent in C#, using the RegionInfo class or any other way? For example, you give the country name "Denmark" and it returns "Europe". 回答1: You can store a hash table. The entries will have as key the country name and as value the continent name. Just generate this table from some public database and once you have it you can simply query it. It's also pretty fast. http://www.geonames.org/countries/ You can get from there a database (there is an option to

How to find world region (or country) or language from the windows registry?

旧街凉风 提交于 2020-01-05 09:36:30
问题 I'm working with a very old installer that can read Registry entries but has a difficulty (complex) time executing Windows APIs. I'm trying to detect whether the PC it's being installed on is in Australia. Any ideas? 回答1: This key: HKEY_USERS.DEFAULT\Keyboard Layout\Preload sets the default language for the login screen The different country codes are listed here: http://www.windowsitpro.com/Article/ArticleID/14867/14867.html 回答2: From my testing and the MSDN page below, this will work: HKEY

Why is ᏌᏊ ᎢᏳᎾᎵᏍᏔᏅ ᏍᎦᏚᎩ the native name of the U.S.?

自作多情 提交于 2020-01-01 04:11:11
问题 When I use this code: var ri = new RegionInfo("us"); var nativeName = ri.NativeName; // ᏌᏊ ᎢᏳᎾᎵᏍᏔᏅ ᏍᎦᏚᎩ why is nativeName then the string "ᏌᏊ ᎢᏳᎾᎵᏍᏔᏅ ᏍᎦᏚᎩ" (in Cherokee)? If I change to new RegionInfo("US") (only difference, capital US ), I get instead "United States" . I do know the preferred usage of RegionInfo is to give a specific culture info string such as: new RegionInfo("en-US") new RegionInfo("chr-Cher-US") and so on, and that works. But why is Cherokee preferred over English only if

Get current country and location details using c#

北慕城南 提交于 2019-12-25 07:49:56
问题 I want to know where my application is used. Here is the code for getting the country name and Time zone : TimeZone localZone = TimeZone.CurrentTimeZone; var result = localZone.StandardName; var s = result.Split(' '); Console.WriteLine(s[0]); Console.WriteLine(RegionInfo.CurrentRegion.DisplayName); But my issue is, any one can change the time zone. Based on the time zone I may get wrong name. And the region settings is used as united states which cannot be changed. Because all the users has

Country name to ISO 3166-2 code

可紊 提交于 2019-12-22 05:37:08
问题 I know how to convert an ISO 3166-2 code to the full English name, e.g. "US" to "United States" by using RegionInfo . However, how can I do the opposite, i.e. that takes "United States" and returns "US"? 回答1: //Get the cultureinfo RegionInfo rInfo = new RegionInfo("us"); string s = rInfo.EnglishName; //Convert it back CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); CultureInfo cInfo = cultures.FirstOrDefault(culture => new RegionInfo(culture.LCID).EnglishName

How to force culture/region on RegionInfo.DisplayName

别来无恙 提交于 2019-12-11 17:08:33
问题 I'm displaying a country as part of some other information. The country is read out of a database as a country code. This is done like so: Location location = new Location() { Company = reader.GetString("Company"), Address1 = reader.GetString("Address"), Address2 = reader.GetString("Address2", string.Empty), ZipCity = reader.GetString("ZipCity"), Country = new RegionInfo(reader.GetString("Country", string.Empty)).DisplayName, CountryCode = new RegionInfo(reader.GetString("Country", string

Country name to ISO 3166-2 code

烈酒焚心 提交于 2019-12-05 06:48:49
I know how to convert an ISO 3166-2 code to the full English name, e.g. "US" to "United States" by using RegionInfo . However, how can I do the opposite, i.e. that takes "United States" and returns "US"? //Get the cultureinfo RegionInfo rInfo = new RegionInfo("us"); string s = rInfo.EnglishName; //Convert it back CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); CultureInfo cInfo = cultures.FirstOrDefault(culture => new RegionInfo(culture.LCID).EnglishName == s); yesenin The main idea: take all region objects and select from them one which contains given full

.NET RegionInfo class

我的未来我决定 提交于 2019-12-04 12:01:40
问题 When I try to create a new RegionInfo with certain ISO 3166 country codes ("BD" for Bangladesh, "SO" for Somalia, "LK" for Sri Lanka), I get an ArgumentException that says it's not recognized. What's the deal? The Intellisense of RegionInfo(string) says it conforms to ISO 3166, but these country/region codes are not supported? I don't get it. 回答1: .NET doesn't provide all Cultures/Regions out-of-the-box. Note the 'predefined' RegionInfos here: http://msdn.microsoft.com/en-us/library/system

Why is ᏌᏊ ᎢᏳᎾᎵᏍᏔᏅ ᏍᎦᏚᎩ the native name of the U.S.?

随声附和 提交于 2019-12-03 09:52:19
When I use this code: var ri = new RegionInfo("us"); var nativeName = ri.NativeName; // ᏌᏊ ᎢᏳᎾᎵᏍᏔᏅ ᏍᎦᏚᎩ why is nativeName then the string "ᏌᏊ ᎢᏳᎾᎵᏍᏔᏅ ᏍᎦᏚᎩ" (in Cherokee )? If I change to new RegionInfo("US") (only difference, capital US ), I get instead "United States" . I do know the preferred usage of RegionInfo is to give a specific culture info string such as: new RegionInfo("en-US") new RegionInfo("chr-Cher-US") and so on, and that works. But why is Cherokee preferred over English only if I use lower-case us ? (Seen on Windows 10 (version 1803 "April 2018 Update"), .NET Framework 4.7.2.)