How to get country name

前端 未结 1 839
暖寄归人
暖寄归人 2021-02-12 16:36

I used the code below to get the list of culture type, is there a way on how to get just the country name?

Thank you



        
相关标签:
1条回答
  • 2021-02-12 17:37

    Well, this regular expression seems to do the job in most cases:

    var regex = new System.Text.RegularExpressions.Regex(@"([\w+\s*\.*]+\))");
    foreach (var item in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
    {
        var match = regex.Match(item.DisplayName);
        string countryName = match.Value.Length == 0 ? "NA" : match.Value.Substring(0, match.Value.Length - 1);
        Console.WriteLine(countryName);
    }
    
    0 讨论(0)
提交回复
热议问题