{"id":3113,"date":"2013-09-26T07:00:00","date_gmt":"2013-09-26T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/09\/26\/dont-forget-unicode-includes-formatting-characters-which-can-be-used-to-influence-output-formatting\/"},"modified":"2013-09-26T07:00:00","modified_gmt":"2013-09-26T07:00:00","slug":"dont-forget-unicode-includes-formatting-characters-which-can-be-used-to-influence-output-formatting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130926-00\/?p=3113","title":{"rendered":"Don&#039;t forget, Unicode includes formatting characters which can be used to influence output formatting"},"content":{"rendered":"<p>\nConsider this simple function:\n<\/p>\n<pre>\nvoid Reminder(HWND hwnd)\n{\n    MessageBoxW(nullptr,\n        L\"Please print out this form in triplicate \"\n        L\"and bring it to the assistance desk \"\n        L\"on level 2.\",\n        L\"Reminder\", MB_OK);\n}\n<\/pre>\n<p>\nDepending on your screen resolution and font choices, this may\nend up displaying like this:\n<\/p>\n<table BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" TITLE='Message dialog with a line break that puts the number 2 on a line by itself.' STYLE=\"color: black;background-color: #d4d0c8;border-width: 2px;border-style: outset;font-size: 9pt;width: 38em;font-family: Segoe UI, Tahoma, MS Sans Serif, Arial, sans-serif\">\n<tr BGCOLOR=\"#0a246a\" STYLE=\"padding: 2px;font-size: 8pt;font-family: Tahoma, MS Sans Serif, Arial, sans-serif\">\n<td ALIGN=\"right\" STYLE=\"padding: 4px 2px 4px 4px\">\n    <b STYLE=\"float: left;color: white\">Reminder<\/b>\n    <span STYLE=\"background-color: #d4d0c8;border: solid 1px white;border-bottom-color: #404040;border-right-color: #404040;margin: 2px\">\n      <span STYLE=\"border: solid 1px transparent;border-right-color: #808080;border-bottom-color: #808080\">\n        <font FACE=\"Marlett\"><!--[if IE]&gt;s&lt;![endif]-->&#xF073;<\/font>\n      <\/span>\n    <\/span>\n    <span STYLE=\"background-color: #d4d0c8;border: solid 1px white;border-bottom-color: #404040;border-right-color: #404040\">\n      <span STYLE=\"border: solid 1px transparent;border-right-color: #808080;border-bottom-color: #808080\">\n        <font FACE=\"Marlett\"><!--[if IE]&gt;r&lt;![endif]-->&#xF072;<\/font>\n      <\/span>\n    <\/span>\n  <\/td>\n<\/tr>\n<tr>\n<td STYLE=\"padding: 10px\">\n        Please print out this form in triplicate\n        and bring it to the assistance desk on level<br \/>2.\n  <\/td>\n<\/tr>\n<tr>\n<td STYLE=\"padding: 10px\" ALIGN=\"center\">\n    <button STYLE=\"margin-right: 5px;width: 5em;height: 2em;font-size: inherit;border: solid 2px white outset;border-bottom: solid 2px #808080 ridge;border-right: solid 2px #808080 ridge;background-color: #d4d0c8\">OK<\/button>\n  <\/td>\n<\/tr>\n<\/table>\n<p>\nThat line break was awfully unfortunate,\nstranding the number 2 on a line by itself.\n(In publishingspeak, this is known as a <i>orphan<\/i>.)\n<\/p>\n<p>\nYou can&#8217;t control\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/06\/24\/10178386.aspx\">\nwhere the <code>Message&shy;Box<\/code> function will insert line breaks<\/a>,\nbut you can try to influence it with the use of Unicode formatting characters.\nHere, we can change the space before the 2 to a Unicode\nnon-breaking space, U+00A0.\n<\/p>\n<pre>\nvoid Reminder(HWND hwnd)\n{\n    MessageBoxW(nullptr,\n        L\"Please print out this form in triplicate \"\n        L\"and bring it to the assistance desk \"\n        L\"on level\" <font COLOR=\"blue\">L\"\\u00A0\"<\/font> L\"2.\",\n        \/\/ could also have been written\n        \/\/ L\"on level<font COLOR=\"blue\">\\u00A0<\/font>2.\",\n        \/\/ but is harder to read\n        L\"Reminder\", MB_OK);\n}\n<\/pre>\n<p>\nThe result is slightly less awful.\n<\/p>\n<table BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" TITLE='Message dialog with a line break that puts the number 2 on a line by itself.' STYLE=\"color: black;background-color: #d4d0c8;border-width: 2px;border-style: outset;font-size: 9pt;width: 38em;font-family: Segoe UI, Tahoma, MS Sans Serif, Arial, sans-serif\">\n<tr BGCOLOR=\"#0a246a\" STYLE=\"padding: 2px;font-size: 8pt;font-family: Tahoma, MS Sans Serif, Arial, sans-serif\">\n<td ALIGN=\"right\" STYLE=\"padding: 4px 2px 4px 4px\">\n    <b STYLE=\"float: left;color: white\">Reminder<\/b>\n    <span STYLE=\"background-color: #d4d0c8;border: solid 1px white;border-bottom-color: #404040;border-right-color: #404040;margin: 2px\">\n      <span STYLE=\"border: solid 1px transparent;border-right-color: #808080;border-bottom-color: #808080\">\n        <font FACE=\"Marlett\"><!--[if IE]&gt;s&lt;![endif]-->&#xF073;<\/font>\n      <\/span>\n    <\/span>\n    <span STYLE=\"background-color: #d4d0c8;border: solid 1px white;border-bottom-color: #404040;border-right-color: #404040\">\n      <span STYLE=\"border: solid 1px transparent;border-right-color: #808080;border-bottom-color: #808080\">\n        <font FACE=\"Marlett\"><!--[if IE]&gt;r&lt;![endif]-->&#xF072;<\/font>\n      <\/span>\n    <\/span>\n  <\/td>\n<\/tr>\n<tr>\n<td STYLE=\"padding: 10px\">\n        Please print out this form in triplicate\n        and bring it to the assistance desk on<br \/>level&nbsp;2.\n  <\/td>\n<\/tr>\n<tr>\n<td STYLE=\"padding: 10px\" ALIGN=\"center\">\n    <button STYLE=\"margin-right: 5px;width: 5em;height: 2em;font-size: inherit;border: solid 2px white outset;border-bottom: solid 2px #808080 ridge;border-right: solid 2px #808080 ridge;background-color: #d4d0c8\">OK<\/button>\n  <\/td>\n<\/tr>\n<\/table>\n<p>\nUnfortunately,\nI haven&#8217;t had much luck with\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/12\/13\/10246957.aspx\">\nthe soft hyphen<\/a>,\nbut the zero-width space seems to work.\n<\/p>\n<pre>\n    MessageBoxW(nullptr,\n        L\"Gooooooo\\u200Booooooo\\u200Booooooo\\u200Booooooo\\u200B\"\n        L\"ooooooo\\u200Booooooo\\u200Booooooo\\u200Booooooo\\u200B\"\n        L\"ooooooo\\u200Booooooo\\u200Booooooo\\u200Booooooo\\u200B\"\n        L\"ooooooo\\u200Booooooo\\u200Booooooo\\u200Booooooo\\u200B\"\n        L\"ooooooo\\u200Bal!\",\n        L\"Gentle reminder\", MB_OK);\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Consider this simple function: void Reminder(HWND hwnd) { MessageBoxW(nullptr, L&#8221;Please print out this form in triplicate &#8221; L&#8221;and bring it to the assistance desk &#8221; L&#8221;on level 2.&#8221;, L&#8221;Reminder&#8221;, MB_OK); } Depending on your screen resolution and font choices, this may end up displaying like this: Reminder &#xF073; &#xF072; Please print out this form in [&hellip;]<\/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-3113","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Consider this simple function: void Reminder(HWND hwnd) { MessageBoxW(nullptr, L&#8221;Please print out this form in triplicate &#8221; L&#8221;and bring it to the assistance desk &#8221; L&#8221;on level 2.&#8221;, L&#8221;Reminder&#8221;, MB_OK); } Depending on your screen resolution and font choices, this may end up displaying like this: Reminder &#xF073; &#xF072; Please print out this form in [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3113","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=3113"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3113\/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=3113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}