Convert string to int error
-
Thursday, December 02, 2010 10:01 AM
Hi everyone...
I have an emulator with windows mobile 6 and i have one aplication run in it.
I have a silly question, when i try convert a string to a int number, I have the following exception:
FormatException in System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider) in System.Int32.Parse(String s, IFormatProvider provider) in System.Convert.ToInt32(String value)
I am using these methods to convert, but i have the same error:
int i = Int32.Parse(data[2].ToString()); int j = Convert.ToInt32(data[2].ToString());
Anybody can help me please?
All Replies
-
Thursday, December 02, 2010 3:18 PM
All I can think of is that the string is not in the correct format for conversion to int.
Can you check what the value of data[2].ToString() is?
-
Thursday, December 02, 2010 4:02 PM
Hi Prabhuk...
The problem was the value, not the type of object inside of data[2], but the value of the variable. Variable have the year on the local machine.
In my computer is 2010, but in my emulator (I check the regional definitions but I can not change)is only 10 :(
When I try construct an object of DateTime, I have the error.
Thanks for your help
-
Tuesday, December 07, 2010 7:10 AMModerator
Hi,
Did you set a breakpoint at it? Then watch the value of data[2].ToString()
Regards
Jesse
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
Tuesday, December 07, 2010 8:39 AM
Hi Jervazio,
Then main reason behind to get error. Then value of data[2].ToString() is not correct basically what happen when you are trying to convert any number value which is store in data[2] in string datatype then only you are able to parse the string value in to integer,int value1 = int.Parse("10"); // Correct string for parsing string to integer
int value2 = int.Parse("10-12"); // wrong string for parsing string to integer
int value3 = int.Parse("10.1"); // wrong string for parsing string to integer
So make sure that what exactly value of data[2].ToString()
Hope it helps
- Pavan Pareta If you find my post is helpful for you then mark as a answer.- Marked As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Thursday, December 09, 2010 8:21 AM
-
Wednesday, December 08, 2010 9:25 AMModerator
Hi,
I'm very interested in hearing more about your issue, did you solve your problem?
If so please share the solution with us and mark the right answers.
If not please let me know and I will tray to help you find further solutions.
Have a nice day!
Jesse
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

