0

A friend has some C# code on a machine that is returning CJK characters when ToUpper and ToLower are called on strings. ToUpperInvariant appears to work.

Here are some of the results:

//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, and System.Threading.Thread.CurrentThread.CurrentCulture all return the same culture (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 

The culture info has UseUserOverride set to true, but passing in a culture with that set to false provides the same results:

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

CultureInfo.CurrentCulture.TextInfo looks benign as well (ANSICodePage is 1252 and OEMCodePage is 437).

What's going on here? Is there perhaps something wrong with the hardware?

Millie Smith
  • 4,536
  • 2
  • 24
  • 60
  • I'm assuming when you specify "on a machine" that it means you have tried this code on another machine and it's fine? – Dave Zych Jan 27 '16 at 22:36
  • @DaveZych yes. Works fine on my machine. It's a machine he got from QA. – Millie Smith Jan 27 '16 at 22:38
  • Well... this may not be something that SO can help me out with. Apparently calling `str.ToUpper()` returns a different result than `str.ToUpper().ToUpper()`, etc... – Millie Smith Jan 27 '16 at 22:41

0 Answers0