Search Unity

Question int.Parse not respecting CultureInfo

Discussion in 'Editor & General Support' started by mvaz_p, Jun 29, 2021.

  1. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    I've been having some issues parsing numbers with the "he-IL" (hebrew) CultureInfo and found out some strange situations.
    This doesn't work in Unity:

    Code (CSharp):
    1. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("he-IL");
    2. int.Parse("+26", System.Globalization.CultureInfo.InvariantCulture);

    But it works with C# REPL:
    Code (CSharp):
    1. csharp> System.Threading.Thread.CurrentThread.CurrentCulture;
    2. he-IL                                                                                                                                                
    3. csharp> int.Parse("+26", System.Globalization.CultureInfo.InvariantCulture;
    4. 26
    So I'm kinda lost here, it seems that the int.Parse while running in Unity is ignoring the culture parameter, at least for this locale.