views:

32

answers:

1

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 ?

+2  A: 
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;
Serkan Hekimoglu
I could not make it work. Can you please give more details.
Samir