In an earlier article, I discussed how the Char.IsDigit() method and its Win32 counterpart, GetStringTypeEx report things to be digits that aren’t just “0” through “9”. If you really care just about “0” through “9”, then you can test for them explicitly. For example, as a regular expression, use [0-9] instead of \d. Alternatively, for a regular expression, you can enable ECMA mode via RegexOptions.ECMAScript. Note that this controls much more than just the interpretation of the \d character class, so make sure to read carefully to ensure that you really want all the ECMA behavior. It has been pointed out to me that there is a way to convert all those “strange” digits to the “0” through “9” range, namely by calling the FoldString function with the MAP_FOLDDIGITS flag. (I put the word “strange” in quotation marks because of course they aren’t strange at all. Just different.) This converts digits but doesn’t help with decimal points, so you still have to deal with correctly interpreting “1,500” as either “one thousand five hundred” (as it would be in the United States) or “one and a half” (as it would be in most of Europe). For that, you need to call GetLocaleInfo to get the LOCAL_SDECIMAL and LOCAL_STHOUSAND strings.
April 16th, 2004
Mapping all those "strange" digits to "0" through "9"
Category
Topics
Author
Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.
0 comments