也許有人知道,.NET Framework 4.0中CultureInfo.Name屬性的最大可能長度是多少。CultureInfo.Name屬性的最大長度
回答
它11.下面是代碼:
var count = CultureInfo.GetCultures(CultureTypes.AllCultures)
.Select(ci => ci.Name.Length)
.Max();
根據下面的代碼:
public static void Test()
{
var culturesNames = from c in CultureInfo.GetCultures(CultureTypes.AllCultures)
select new { c.DisplayName, c.DisplayName.Length, c.Name };
foreach (var ci in culturesNames.OrderBy((o) => o.Length))
{
Console.WriteLine("{0} : {2} {1}", ci.DisplayName, ci.Length, ci.Name);
}
}
的最大長度爲50 不要忘了開發人員可以創建自定義的文化信息。
CultureInfo.Name和CultureInfo.DisplayName是不同的東西。我需要最長的可能長度CultureInfo.Name – msi 2011-02-01 13:14:52
答:84
文件:(在評論感謝@lethek) http://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.cultureandregioninfobuilder%28v=vs.100%29.aspx
我是能夠使使用CultureAndRegionInfoBuilder類是長84個字符,下面的代碼一種新的文化。
CultureAndRegionInfoBuilder將不允許超過84個字符的名稱。要獲得84個字符,您需要確保您用「 - 」分隔的每個部分的長度不能超過8個字符。你不能僅僅創建一個名爲「ThisIsLongerThan8Characters」的文化,因爲它長於8個字符而沒有分隔符。 (請注意,我認爲你可以用同樣的方式使用「_」,但我沒有嘗試過)
爲了使下面的代碼正常工作,你需要引用sysglobl
程序集並導入System.Globalization
命名空間。
下面的代碼嘗試在開始和結束時取消註冊文化。一旦註冊完成,我加載一個CultureInfo,格式化日期並顯示名稱和顯示名稱。
希望這是有幫助的。
string cultureName = "qwertyui-12345678-qwertyui-12345678-qwertyui-12345678-qwertyui-12345678-qwertyui-123";
Console.WriteLine("MAX LENGTH: " + cultureName.Length);
try {
CultureAndRegionInfoBuilder.Unregister(cultureName);
} catch {
Console.WriteLine("Cannot remove culture");
}
CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder(cultureName , CultureAndRegionModifiers.None);
CultureInfo ci = new CultureInfo("en-AU");
RegionInfo ri = new RegionInfo("US");
builder.LoadDataFromCultureInfo(ci);
builder.LoadDataFromRegionInfo(ri);
builder.Register();
CultureInfo info = new CultureInfo(cultureName);
Console.WriteLine(DateTime.Now.ToString(info.DateTimeFormat.LongDatePattern));
Console.WriteLine(info.Name);
Console.WriteLine(info.DisplayName);
try {
CultureAndRegionInfoBuilder.Unregister(cultureName);
} catch {
Console.WriteLine("Cannot remove culture");
}
- 1. ie中的最大長度onclick屬性
- 2. 最大長度屬性的角度驗證消息
- 3. 劍道Masked Textbox最大和最小長度屬性
- 4. CSS最大高度屬性
- 5. Firebase的用戶屬性值的最大長度是多少?
- 6. Zend_Currency的Symbol屬性的最大長度是多少?
- 7. 德爾福屬性中的字符串的最大長度TMemo
- 8. textarea上的最大長度屬性不適用於手機
- 9. 最大長度在煎茶觸摸numberfield的屬性
- 10. EF屬性上的最大長度不起作用
- 11. window.returnValue屬性允許的最大長度是多少? (JavaScript)
- 12. 帶屬性和最大長度限制的XSD元素
- 13. SSIS:DtsContainer名稱屬性,最大長度是多少?
- 14. 使用AngularJS設置html5輸入最大長度屬性
- 15. 如何設置DIV最大值長度屬性CONTENTEDITABLE
- 16. 改變所有字符串屬性最大長度
- 17. 最大NVARCHAR長度
- 18. UITextView最大長度
- 19. JAVA_TOOL_OPTIONS最大長度
- 20. CSS最大長度
- 21. 最大URL長度
- 22. BindingSource.Filter最大長度
- 23. TextArea最大長度?
- 24. CString最大長度
- 25. 與最大長度
- 26. MaskedTextBox最小/最大長度
- 27. openID的最大長度
- 28. LPAD列的最大長度
- 29. [NSXMLNode stringValue]的最大長度
- 30. 字節[]的最大長度?
謝謝。這對我來說是可以接受的。但是很奇怪的是,微軟在其Commerce Server中使用了17個字符來存儲CultureInfo.Name:http://technet.microsoft.com/en-us/library/microsoft.commerceserver.marketing.languagestring.culturecode(d = lightweight ,v = CS.90).aspx – msi 2011-02-01 13:19:41
不客氣。不要忘記勾選答案;) – gor 2011-02-01 16:25:24