{"id":101058,"date":"2019-02-19T07:00:00","date_gmt":"2019-02-19T22:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=101058"},"modified":"2019-03-12T23:57:23","modified_gmt":"2019-03-13T06:57:23","slug":"20190219-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190219-00\/?p=101058","title":{"rendered":"How do I convert all these strange Unicode digits into the ones I remember from Sesame Street?"},"content":{"rendered":"<p>Suppose you have a Unicode string and you want to do something mathematical with it. You know how to parse DIGIT ZERO &#8220;0&#8221; through DIGIT NINE &#8220;9&#8221; but the string may contain Unicode digits like ARABIC-INDIC DIGIT SIX &#8220;<span LANG=\"ar\">&#x666;<\/span>&#8221; or DEVANAGARI DIGIT SEVEN &#8220;<span LANG=\"hin\">&#x96D;<\/span>&#8220;, and you want to support those too. <\/p>\n<p>Help here comes from the <code>Fold&shy;String<\/code> function. <\/p>\n<pre>\nint result = FoldString(MAP_FOLDDIGITS, originalString, -1,\n                        resultBuffer, resultBufferSize);\n<\/pre>\n<p>You give the <code>Fold&shy;String<\/code> function an input buffer, either with an explicit character count, or with <code>-1<\/code> 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 <code>MAP_<\/code><code>FOLD&shy;DIGITS<\/code>, which means to convert all decimal digits to DIGIT ZERO &#8220;0&#8221; through DIGIT NINE &#8220;9&#8221;. <\/p>\n<p>Now you can do your magic mathematical thing with a known number representation. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Know when to fold&#8217;em.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-101058","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Know when to fold&#8217;em.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/101058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=101058"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/101058\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=101058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=101058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=101058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}