问题描述
我使用下面的代码来获取文化类型的列表,是他们如何获得国家名称的方法?
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); }
这篇关于如何获取国家名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!