如何获取国家名称 [英] How to get country name

查看:230
本文介绍了如何获取国家名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码来获取文化类型的列表,是他们如何获得国家名称的方法?

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

谢谢

        static void Main(string[] args)
       {

        StringBuilder sb = new StringBuilder();

        foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
        {
            sb.Append(ci.DisplayName);
            sb.AppendLine();
        }
        Console.WriteLine(sb.ToString());
        Console.ReadLine();


    }

strong>

Sample Output:

西班牙语(波多黎各)

西班牙语(美国)

code> var regex = new System.Text.RegularExpressions.Regex(@([\w + \s * \。*] + \)));
foreach(CultureInfo.GetCultures(CultureTypes.SpecificCultures)中的var项)
{
var match = regex.Match(item.DisplayName);
string countryName = match.Value.Length == 0? NA:match.Value.Substring(0,match.Value.Length - 1);
Console.WriteLine(countryName);
}

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); }

这篇关于如何获取国家名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆