That's funny, they look like digits!

by Michael S. Kaplan, published on 2007/03/01 03:01 -05:00, original URI:

Boris asked me:

Hi Michael. 

I saw the thread about parsing the numbers of other language digits, however I have extra question.  The Char.IsDigit does recognizes below data:

char c1 = '\uFF12';
char c2 = '2'; 

as digits and is returning true for each of them. 

Does it mean that the FormatException “Input string was not in a correct format” in Int32.Parse() with this value as argument

i = Int32.Parse(c1.ToString());
i = Int32.Parse(c2.ToString());

is just the limitation of particular NET API Int32.Parse()?


A very good question!

Indeed, as Boris suspected it is related to the issue I talked about here.

Though it is a little bit more complicated since clearly 0123456789 looks like a bunch of digits, which makes it a much tougher sell to have it throw when you try to parse something and it throws even though a six year old could probably parse it....

Back when I was consulting, there were a few times for Japanese customers that I would parse these digits since it was quite easy to have someone typing without noticing they were in fullwidth mode on their IME, in which case they'd have these digits show up. Popping up an error is easy but it is hardly very polite when it is so obvious what the intent was!

Luckily, any of the following:

will all return a number back, so it is easy enough to do the parsing yourself if you want to.

Now there are some specific problems with trying to upgrade the .NET Framework to be as smart as that six year old, which I will talk about soon. :-)


This post brought to you by  (U+ff12, a.k.a. FULLWIDTH DIGIT TWO)

no comments

referenced by

2007/11/09 If you get a yen for something a bit wider you might be out of luck

go to newer or older post, or back to index or month or day