Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

c# - Converting country codes in .NET

In .NET is there any way to convert from three letter country codes (defined in ISO 3166-1 alpha-3) to two letter language codes (defined in ISO 3166-1 alpha-2) eg. convert BEL to BE?

Have looked at the RegionInfo class in System.Globalization but the constructor does not seem to support the three letter codes.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The RegionInfo class does know the three-letter code (in the ThreeLetterISORegionName property), but I don’t think there is a way to get RegionInfo based on this code, you would need to enumerate all regions and add them to your own dictionary, with the three-letter code as a key.

However, I think the .NET Framework uses RegionInfo to work with cultures, not countries in the ISO 3166-1 sense. Therefore, many countries from the ISO 3166-1 standard are not available (try e.g. SX). I guess you should create your own country codebook.

Edit: From 246 countries in my current country codebook, RegionInfo is available for 125 of them, the rest (121) are not supported. Conclusion: This is not a good way to get a country codebook.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...