Given a CultureInfo object, how do I get the two character ISO 3166 Country Code? E.g. from en-US, I want US and from en-GB, I want GB. I also need to handle cases where the culture may not have a country code.
How to get ISO 3166 Country Code from CultureInfo in .NET
1.1k Views Asked by Muhammad Rehan Saeed At
2
There are 2 best solutions below
0
Sasha Ibraimov
On
You can use this package
This library that provides access to ISO standards, including ISO 639 (language codes), ISO 3166 (country codes), and ISO 4217 (currency codes).
Example:
Country[] countries = Countries.Collection.Where(c => c.Name[0] == 'A').ToArray();
foreach (Country country in countries)
{
Language[] langs = country.GetLanguages();
Currency[] currencies = country.GetCurrencies();
string langsColumn = string.Join(',', langs.Select(l => l.Name));
string currenciesColumn = string.Join(',', currencies.Select(l=>l.Alpha3));
Console.WriteLine($"{country.Alpha2};{country.Name};{currenciesColumn};{langsColumn}");
}
Related Questions in .NET
- Does compiler optimize operation on const variable and literal const number?
- What is the point of definnig Asp.net Intrinsic Objects In different places and what is the different betwen them?
- Deleting Orphans with Fluent NHibernate
- IOrderedEnumerable to vb.net IOrderedEnumerable Conversion
- What is this namespace ITypeOfObjectsBoundToListBox ? Couldn't find it
- .net rest service with JSON string and consumed with java client
- What is best way to check if any of the property of object is null or empty?
- Telerik's WPF RadColorPicker NoColorText property not working
- Possible consequences of duplicate ProgId for different classes
- How are multiple requests to Task.Run handled from a resource management standpoint?
- Optimizing C++ call from C#
- Make a per-web-application object available to Web API and SignalR controllers
- System.ComponentModel.DataAnnotations.Schema namespace conflict
- LINQ Except/Distinct based on few columns only, to not add duplicates
- Not displaying content by its URL string - absolute urls
Related Questions in .NET-CORE
- NLog with DNX Core 5.0
- How should I reference HttpClient for dnx451 and dnxcore50?
- DNX Core 5.0 library to target any platform. No System.Random class. Workarounds or options?
- Kestrel Running which framework?
- Directory.CreateDirectory not exists in .NET Core
- asp.net dnxcore50 load assembly by file path
- .NET Core doesn't depend on any installation?
- Why is linq to object implementing iterators manually?
- Microsoft Band and WPF
- Determine port in asp.net core
- ASP.NET Core IISIntegration.Tools and .NET Framework
- ANTLR 4.5.3 C# lexer fails to initialize (ATN UUID error)
- Opening Visual Studio 2017 projects in Visual Studio 2015
- dotnetCore (1.0.0-preview2-1-003177) - build warnings as errors - how?
- How to implement interface of C# use COM of native C++?
Related Questions in CULTUREINFO
- ToLower vs ToLowerInvariant
- System.Globalization.RegionInfo complete list of valid culture inputs
- Validate double number in current culture
- Get language and country code (ISO 639-1)
- Parse/Read a double at a known start position in a string
- DateTime get the letters representing day, month, year from the currentculture
- .net How do I know 12/24 hour format when I know the culture Info
- Parsing a string with a number on basis of culture
- Setting the Culture of only a single view, not the entire program
- Why does Convert.ToInt32 accept IFormatProvider?
- .Net CurrentCulture ShortDateFormat doesn't update according to PC regional settings
- Format not getting applied in French culture
- What is the use of CultureInfo.InvariantCulture.Calendar.GetDayOfWeek?
- Is this safe, or will it only work in English-speaking countries?
- When to pass Culture when comparing strings using Assert.AreEqual() in C#
Related Questions in CULTURE
- how to extract characters of a language
- WPF application with different CurrentCulture and CurrentUICulture
- MVC Controller receives DateTime parsed as different culture from CurrentThread.CurrentCulture
- Formatting number in European format with two decimals
- Using StringComparer with StringBuilder to search for a string
- Change the current culture of a Powershell session, v3.0+ specific
- WPF StringFormat [Numbers] on Culture Change
- Opposite method to toLocaleDateString
- how to get list of installed cultures on computer?
- How to set two different Cultures for two different Controls on a single Form at the same time?
- changing culture(language) when button click
- Strange Control Characters in C# DataTable results, not in SSMS or VB.NET results
- how to handle culture in double parsing in c#?
- Receiving an Arabic datetime error in asp.net
- WMI Query on a non english system
Related Questions in ISO-3166
- NetSuite data import with country code?
- How to convert country names to ISO 3166-1 alpha-2 values in arm template
- Country name to ISO 3166-2 code
- Retrieving Country (ISO 3166-1) and Region (ISO 3166-2) codes from address (using existing web services)
- ISO3166 not importing method properly -Pycharm
- How to get the numeric code of all ISO 3166-1 countries in C#
- How to get a country's official name from a Java Locale?
- Get ISO 3166-2 Code from HERE Geocoder API
- Get ISO 3166-2 Code from Bing Maps Locations API
- How to get ISO 3166-1 compatible country code?
- How to convert country names to ISO 3166-1 alpha-2 values, using python
- ISO 3166-1 to woeid
- ISO 3166-1 alpha-2 comma separated values
- Unsupported ISO 3166 country ES?
- Locale and ISO3CountryCodes
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Use RegionInfo-class to retrieve two (or three) letter iso region name:
You might want to catch possible exception that will happen if you try to pass invalid value to the constructor.