{"id":112307,"date":"2026-05-07T07:00:00","date_gmt":"2026-05-07T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112307"},"modified":"2026-05-07T09:44:24","modified_gmt":"2026-05-07T16:44:24","slug":"20260507-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260507-00\/?p=112307","title":{"rendered":"When you upgrade your resource strings to Unicode, don&#8217;t forget to specify the L prefix"},"content":{"rendered":"<p>Some time ago, I discussed how <a title=\"The Resource Compiler defaults to CP_ACP, even in the face of subtle hints that the file is UTF-8\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190607-00\/?p=102569\"> the Resource Compiler defaults to CP_ACP, even in the face of subtle hints that the file is UTF-8<\/a>.<\/p>\n<p>After yet another incident of <a title=\"Making sure the Microsoft Visual C++ compiler chooses the right source encoding\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20241231-00\/?p=110696\"> Visual Studio secretly changing the file encoding from 1252 to UTF-8<\/a> and breaking all non-ASCII strings, combined with <a title=\"How various git diff viewers represent file encoding changes in pull requests\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20241230-00\/?p=110692\"> Azure DevOps and Visual Studio simply ignoring encoding changes when showing diffs<\/a>, a colleague decided to solve the problem once and for all by using explicit Unicode escapes <tt>\\x####<\/tt> to represent non-ASCII characters. That way, it doesn&#8217;t matter whether the file encoding is 1252 or UTF-8 because the two code pages agree on the common ASCII subset.<\/p>\n<p>What used to be<\/p>\n<pre>IDS_AWESOME \"That\u2019s great!\"\r\n<\/pre>\n<p>was changed to<\/p>\n<pre>IDS_AWESOME \"That\\x2019s great!\"\r\n<\/pre>\n<p>Unfortunately, the resulting string that appeared on screen was<\/p>\n<blockquote class=\"q\"><p>That 19s great!<\/p><\/blockquote>\n<p>What went wrong?<\/p>\n<p>If you are encoding Unicode into your string, you have to put an <code>L<\/code> prefix on the quoted string. Otherwise, the <tt>\\xABCD<\/tt> sequence is interpreted as an 8-bit <tt>\\xAB<\/tt> escape sequence, followed by two literal characters <tt>CD<\/tt>. In this case, the <tt>\\x2019<\/tt> was interpreted as <tt>\\x20<\/tt> (which encodes a space) followed by the literal characters <tt>19<\/tt>, resulting in the string <tt>That\u242319s great!<\/tt>.<\/p>\n<p>The correct conversion includes the <code>L<\/code> prefix.<\/p>\n<pre>IDS_AWESOME <span style=\"border: solid 1px currentcolor;\">L<\/span>\"That\\x2019s great!\"\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Otherwise, it&#8217;ll get mapped back down to the 8-bit code page.<\/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-112307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Otherwise, it&#8217;ll get mapped back down to the 8-bit code page.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112307","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=112307"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112307\/revisions"}],"predecessor-version":[{"id":112308,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112307\/revisions\/112308"}],"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=112307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}