ToUpper和ToLower返回CJK字符

时间:2016-01-27 22:30:20

标签: c# cultureinfo

当在字符串上调用ToUpper和ToLower时,朋友在返回CJK字符的计算机上有一些C#代码。 ToUpperInvariant似乎有效。

以下是一些结果:

//precondition:
var viewName = "AdvancedView";

viewName.ToUpper()[0]; //23429 '宅'
viewName.ToUpper()[1]; //13723 '㖛'

"astring".ToUpper(); //"؜㪑瓁ᩤ哚ὸ悕"

"hello".ToUpper(System.Globalization.CultureInfo.CreateSpecificCulture("en-US")) //"粩ᕿዳዳ㐧" 
"hello".ToLower() //"ሼ㉱㰖㰖晐"
"hello".ToUpper().ToLower() //"蠼䫡贫贫肅"

viewName[0]; //65 'A'
viewName[1]; //100 'd'
viewName[2]; //118 'v'

viewName.ToUpperInvariant() //ADVANCEDVIEW

CultureInfo.CurrentCulture,CultureInfo.CurrentUICulture和System.Threading.Thread.CurrentThread.CurrentCulture都返回相同的文化(en-US):

System.Threading.Thread.CurrentThread.CurrentCulture
{en-US}
    calendar: {System.Globalization.GregorianCalendar}
    Calendar: {System.Globalization.GregorianCalendar}
    CompareInfo: {CompareInfo - en-US}
    compareInfo: {CompareInfo - en-US}
    CreatedDomainID: 0
    cultureID: 127
    CultureTypes: SpecificCultures | InstalledWin32Cultures | FrameworkCultures
    DateTimeFormat: {System.Globalization.DateTimeFormatInfo}
    dateTimeInfo: {System.Globalization.DateTimeFormatInfo}
    DisplayName: "English (United States)"
    EnglishName: "English (United States)"
    HasInvariantCultureName: false
    IetfLanguageTag: "en-US"
    IsNeutralCulture: false
    IsReadOnly: true
    IsSafeCrossDomain: false
    KeyboardLayoutId: 1033
    LCID: 1033
    m_consoleFallbackCulture: null
    m_createdDomainID: 0
    m_cultureData: {System.Globalization.CultureData}
    m_dataItem: 0
    m_isInherited: false
    m_isReadOnly: true
    m_isSafeCrossDomain: false
    m_name: "en-US"
    m_nonSortName: "en-US"
    m_parent: {en}
    m_sortName: "en-US"
    m_useUserOverride: false
    Name: "en-US"
    NativeName: "English (United States)"
    NumberFormat: {System.Globalization.NumberFormatInfo}
    numInfo: {System.Globalization.NumberFormatInfo}
    OptionalCalendars: {System.Globalization.Calendar[2]}
    Parent: {en}
    Region: {US}
    regionInfo: {US}
    SortName: "en-US"
    textInfo: {TextInfo - en-US}
    TextInfo: {TextInfo - en-US}
    ThreeLetterISOLanguageName: "eng"
    ThreeLetterWindowsLanguageName: "ENU"
    TwoLetterISOLanguageName: "en"
    UseUserOverride: true 

文化信息将UseUserOverride设置为true,但传入设置为false的文化会提供相同的结果:

var info = new CultureInfo("en-US", false);
str.ToUpper(info); //"㪑瓁ᩤ

CultureInfo.CurrentCulture.TextInfo看起来也很温和(ANSICodePage是1252,OEMCodePage是437)。

这里发生了什么?硬件可能有问题吗?

0 个答案:

没有答案