【问题标题】:How to Convert string (culture != "en-US") to int C# 2005如何将字符串(文化!=“en-US”)转换为 int C# 2005
【发布时间】:2010-07-09 12:22:56
【问题描述】:

C# 2005,我在 Program.cs 中设置了如下文化:

CultureInfo myCulture = new CultureInfo("bn-IN");// like "en-US", "ja-JP" etc...
Thread.CurrentThread.CurrentCulture = myCulture;
Thread.CurrentThread.CurrentUICulture = myCulture;
Application.CurrentCulture = myCulture;

然后在打开应用程序后,我选择我的键盘,然后点击键盘 1,我的语言版本为 1。现在我想将其转换为整数,以便我可以执行加法、减法等操作。所以...

CultureInfo myCulture = Application.CurrentCulture;
myCulture.NumberFormat.DigitSubstitution = DigitShapes.NativeNational;
int i = Convert.ToInt32(textbox1.Text, myCulture.NumberFormat);// this line throws exception with message "Input string was not in a current format"

那么如何将另一种文化(“en-US”除外)中的字符串转换为整数?

【问题讨论】:

    标签: string keyboard integer cultureinfo


    【解决方案1】:
    CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    

    用不同的文化在这里输入你的价值观,然后回到你的旧文化

    Thread.CurrentThread.CurrentCulture = oldCulture;
    

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 2021-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多