Get country code from country full name.
Example: i have an input for country name and i want to convert that country name as country code.
Country Name: India
Country Code : IN
Country Name: United States
Country Code : US
Thanks in advance
Get country code from country full name.
Example: i have an input for country name and i want to convert that country name as country code.
Country Name: India
Country Code : IN
Country Name: United States
Country Code : US
Thanks in advance
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Aug 25, 2021, 4:30 PM EDT
follow my jsfiddle
code is for the country, code, and flag based on your previous question.
Ganesan CRank #369 · 6.8K reputationPosted Aug 25, 2021, 2:21 PM EDT
Try below code. It prints list of coutry with code.
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; public class Program { public static void Main() { CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); List countries = new List(); foreach (CultureInfo ci in cultures) { RegionInfo regionInfo = new RegionInfo(ci.Name); if (countries.Count(x => x.EnglishName == regionInfo.EnglishName) x.EnglishName)) Console.WriteLine(regionInfo.EnglishName + " - " + regionInfo.TwoLetterISORegionName); } }Ganesan CRank #369 · 6.8K reputationPosted Aug 25, 2021, 2:29 PM EDT
If you want coutry code based on country name try below code.
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; public class Program { public static void Main() { var regions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID)); var englishRegion = regions.FirstOrDefault(region => region.EnglishName.Contains("United Kingdom")); var countryAbbrev = englishRegion.TwoLetterISORegionName; Console.WriteLine(countryAbbrev) ; } }Ganesan CRank #369 · 6.8K reputationPosted Aug 25, 2021, 2:55 PM EDT
You can check the below links.
Sachin SinghRank #66 · 26.2K reputationPosted Sep 1, 2021, 1:41 AM EDT
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Aug 25, 2021, 6:35 AM EDT
Priyanka K SRank #1,385 · 1.2K reputationPosted Aug 25, 2021, 7:17 AM EDT
D Developer85 reputationPosted Sep 1, 2021, 1:09 AM EDT