如何将string(culture!=“en-US”)转换为int C#2005

时间:2010-07-09 12:22:56

标签: string keyboard integer cultureinfo

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”除外)转换为整数?

1 个答案:

答案 0 :(得分:2)

CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture;
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

在这里输入不同文化的价值,然后回到原来的文化

Thread.CurrentThread.CurrentCulture = oldCulture;