Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
How to convert the following string to integer or to normal ASCII string

string input = "3285"; //"3285" not equal to "3285"
int no = Convert.ToInt32(input);

It will threw exception


Thanks

What I have tried:

string input = "3285"; //"3285" not equal to "3285"
int no = Convert.ToInt32(input);

It will threw exception
Posted
Updated 21-Mar-16 17:41pm

Of course it will throw an exception. You have white space between each digit in the string. First remove the white space then use the int.TryParse to do your convertions.
 
Share this answer
 
Comments
Member 12287104 22-Mar-16 3:30am    
No, there do not have any space between the digits. The problem is the digits is in not in ASCII. Please copy "3285" & "3285" these and paste to notepad. You will see the different.

Thanks
Quote:
//"3285" not equal to "3285"
All is in the comment, the second 3285 is an integer made of digits, but the one is some unicode that look like digits but is not made of digits.
the "3" is coded in utf-8 as EF BC 93
the "2" is coded in utf-8 as EF BC 92
the "8" is coded in utf-8 as EF BC 98
the "5" is coded in utf-8 as EF BC 95

the "3" is also decoded as U+FF13 FULLWIDTH DIGIT THREE, which is not a digit from the C# point of view.

If this is typical of data you have to handle, you should convert unicode chars to traditional digits first.
 
Share this answer
 
Comments
Member 12287104 22-Mar-16 3:35am    
Any typical way to handle it?
Thanks
Patrice T 22-Mar-16 3:44am    
transcoding.
Just replace the fake digits by real digits.
search replace in a string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900