如何将字符串 (culture != "en-US") 转换为 int C# 2005

发布于 2024-09-08 11:28:13 字数 705 浏览 2 评论 0 原文

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

C# 2005, I have set the culture like below in 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;

Then after opening the application I choose my keyboard, and hit keyboard 1 which puts my language version of 1. Now I want to convert it to integer so that I can perform addition, subtraction etc. So...

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"

so how to convert a string in another culture(other than "en-US") to integer ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风渺 2024-09-15 11:28:13
CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture;
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

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

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

type your value here with different culture and go back to your old culture

Thread.CurrentThread.CurrentCulture = oldCulture;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文