Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How do I convert all these strange Unicode digits into the ones I remember from Sesame Street?


Suppose you have a Unicode string and you want to
do something mathematical with it.
You know how to parse
DIGIT ZERO "0" through DIGIT NINE "9"
but the string may contain Unicode digits like
ARABIC-INDIC DIGIT SIX "٦"
or
DEVANAGARI DIGIT SEVEN
"",
and you want to support those too.



Help here comes from the
Fold­String function.



int result = FoldString(MAP_FOLDDIGITS, originalString, -1,
resultBuffer, resultBufferSize);


You give the Fold­String
function an input buffer,
either with an explicit
character count, or with -1 to indicate
that you want to process up to and including the null
terminator.
You also give it an output buffer.
And you tell it what kind of conversion you want to perform.
In our case, we ask for MAP_FOLD­DIGITS,
which means to convert all decimal digits to
DIGIT ZERO "0" through DIGIT NINE "9".



Now you can do your magic mathematical thing with
a known number representation.

Share the post

How do I convert all these strange Unicode digits into the ones I remember from Sesame Street?

×

Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription

×