Convert ALPHA-2 to ALPHA-3 in C# ASP.net
-
10-07-2019 - |
Question
Is there a quick built in way to convert ALPHA-2 (GB) to ALPHA-3 (GBR) in C# without having to create an array of them all.
Solution
// using System.Globalization;
RegionInfo info = new RegionInfo("GB");
string ISOAlpha3 = info.ThreeLetterISORegionName; // ISOAlpha3 == "GBR"
OTHER TIPS
Sorry for bumping an old thread. This do work for GB but RegionInfo will throw an exception for a lot of ALPHA-2 country codes e.g.
new RegionInfo("AF"); // throws an error for Afghanistan
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow