1

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

4

1 回答 1

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

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

Thread.CurrentThread.CurrentCulture = oldCulture;
于 2010-07-09T12:27:23.573 回答