) 호주와 같은 국가 이름이 있습니다.이 경우 AU와 같은 ISO 3166-1 알파 2 코드를 받고 싶습니다. .NET에서 쉽게이 작업을 수행 할 수있는 방법이 있습니까?국가 이름 (ISO 3166-1 알파 2 코드
0
A
답변
2
국가 이름을 2 알파 ISO 코드로 변환 할 수있는 기능은 없습니다.
둘 사이에 매핑 할 사전을 만들 수 있습니다.
var countryToISO2Map = new Dictionary<string,string>{
{"Australia", "AU"},
...
};
0
국가 코드를 http://country.io/names.json에서 JSON으로 매핑 할 수 있습니다.
var countries = codes.ToDictionary(x => x.Value, x => x.Key);
그러면 다음과 같이 쉽게 새 사전에서 국가 코드를 얻을 수 있습니다.
3
비슷한 문제는 Country name to ISO 3166-2 code
/// <summary>
/// English Name for country
/// </summary>
/// <param name="countryEnglishName"></param>
/// <returns>
/// Returns: RegionInfo object for successful find.
/// Returns: Null if object is not found.
/// </returns>
static RegionInfo getRegionInfo (string countryEnglishName)
{
//Note: This is computed every time. This may be optimized
var regionInfos = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Select(c => new RegionInfo(c.LCID))
.Distinct()
.ToList();
RegionInfo r = regionInfos.Find(
region => region.EnglishName.ToLower().Equals(countryEnglishName.ToLower()));
return r;
}
에 요청