Converting country codes in .NET

前端 未结 10 1685
难免孤独
难免孤独 2020-12-04 23:55

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

10条回答
  •  眼角桃花
    2020-12-05 00:42

    You can try using .NET RegionInfo as it is described HERE:

    using System;
    using System.Globalization;
    
    public class SamplesRegionInfo  {
    
       public static void Main()  {
    
          // Displays the property values of the RegionInfo for "US".
          RegionInfo myRI1 = new RegionInfo( "US" );
          Console.WriteLine( "   Name:                         {0}", myRI1.Name );
          Console.WriteLine( "   DisplayName:                  {0}", myRI1.DisplayName );
          Console.WriteLine( "   EnglishName:                  {0}", myRI1.EnglishName );
          Console.WriteLine( "   IsMetric:                     {0}", myRI1.IsMetric );
          Console.WriteLine( "   ThreeLetterISORegionName:     {0}", myRI1.ThreeLetterISORegionName );
          Console.WriteLine( "   ThreeLetterWindowsRegionName: {0}", myRI1.ThreeLetterWindowsRegionName );
          Console.WriteLine( "   TwoLetterISORegionName:       {0}", myRI1.TwoLetterISORegionName );
          Console.WriteLine( "   CurrencySymbol:               {0}", myRI1.CurrencySymbol );
          Console.WriteLine( "   ISOCurrencySymbol:            {0}", myRI1.ISOCurrencySymbol );
    
       }
    
    }
    
    /*
    This code produces the following output.
    
       Name:                         US
       DisplayName:                  United States
       EnglishName:                  United States
       IsMetric:                     False
       ThreeLetterISORegionName:     USA
       ThreeLetterWindowsRegionName: USA
       TwoLetterISORegionName:       US
       CurrencySymbol:               $
       ISOCurrencySymbol:            USD
    
    */
    

提交回复
热议问题