无论如何要使用完整的显示名称创建cultureInfo 对象的实例:
CultureInfo userCulture = new CultureInfo("Japanese (Japan)");
或将完整的显示名称转换为文化代码:
toCultureCode("Japanese (Japan)");
会回来 "ja-JP"
无论如何要使用完整的显示名称创建cultureInfo 对象的实例:
CultureInfo userCulture = new CultureInfo("Japanese (Japan)");
或将完整的显示名称转换为文化代码:
toCultureCode("Japanese (Japan)");
会回来 "ja-JP"
没有内置的方法可以通过它的英文名称来获取文化,所以你可以写一个:
public static CultureInfo getCultureByEnglishName(String englishName)
{
// create an array of CultureInfo to hold all the cultures found,
// these include the users local culture, and all the
// cultures installed with the .Net Framework
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
// get culture by it's english name
var culture = cultures.FirstOrDefault(c =>
c.EnglishName.Equals(englishName, StringComparison.InvariantCultureIgnoreCase));
return culture;
}
toCultureCode
是ToString
:_
String name = "Japanese (Japan)";
CultureInfo japanCulture = getCultureByEnglishName(name);
Console.Write(japanCulture.ToString()); // -> "ja-JP"
您可以使用 Linq
using System.Linq;
CultureInfo culture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => c.DisplayName == "Japanese (Japan)");