{"id":10401,"date":"2006-05-02T01:04:00","date_gmt":"2006-05-02T01:04:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/05\/02\/em-dash-en-dash-dash-dash-dash\/"},"modified":"2019-02-18T13:21:45","modified_gmt":"2019-02-18T20:21:45","slug":"em-dash-en-dash-dash-dash-dash","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/em-dash-en-dash-dash-dash-dash\/","title":{"rendered":"em dash, en dash, dash, dash, dash&#8230;"},"content":{"rendered":"<p><span><\/p>\n<p class=\"MsoNormal\"><span>Some people have noticed that you can paste examples out of Word documents directly into a PowerShell session. Given all of the typographic tricks that Word does, this is actually much harder than it sounds. Here\u2019s what we do. There&#8217;s a piece of code in the interpreter that takes each of the possible characters and maps it into the canonical representation for that character. So &#8211; an em-dash ([char] 0x2014)&nbsp;or an en-dash ([char] 0x2013)&nbsp;become a simple dash (0x02d). There are also predicate functions that return true it the character is a single quote, double quote or a dash. The code is (approximately):<\/span><\/p>\n<p class=\"MsoNormal\"><font face=\"Times New Roman\" color=\"#000000\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> enDash = (<\/font><span>char<\/span><font color=\"#000000\">)0x2013;<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> emDash = (<\/font><span>char<\/span><font color=\"#000000\">)0x2014;<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> horizontalBar = (<\/font><span>char<\/span><font color=\"#000000\">)0x2015;<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>\/\/ left single quotation mark<\/span><span><\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> quoteSingleLeft = (<\/font><span>char<\/span><font color=\"#000000\">)0x2018<\/font><span>;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span>\/\/ right single quotation mark<\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> quoteSingleRight = (<\/font><span>char<\/span><font color=\"#000000\">)0x2019;&nbsp; <\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>\/\/ single low-9 quotation mark<\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> quoteSingleBase = (<\/font><span>char<\/span><font color=\"#000000\">)0x201a;&nbsp;&nbsp; <\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>\/\/ single high-reversed-9 quotation mark&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> quoteReversed = (<\/font><span>char<\/span><font color=\"#000000\">)0x201b;&nbsp;<\/font><span> <\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span>\/\/ left double quotation mark<\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> quoteDoubleLeft = (<\/font><span>char<\/span><font color=\"#000000\">)0x201c;&nbsp;&nbsp; <\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>\/\/ right double quotation mark<\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> quoteDoubleRight = (<\/font><span>char<\/span><font color=\"#000000\">)0x201d;&nbsp; <\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>\/\/ low double left quote used in german.<\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>const<\/span><font color=\"#000000\"> <\/font><span>char<\/span><font color=\"#000000\"> quoteLowDoubleLeft = (<\/font><span>char<\/span><font color=\"#000000\">)0x201E;<span><\/span><\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>static<\/span><font color=\"#000000\"> <\/font><span>bool<\/span><font color=\"#000000\"> IsDash(<\/font><span>char<\/span><font color=\"#000000\"> c)<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">{<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">&nbsp;&nbsp;&nbsp; <\/font><span>return<\/span><font color=\"#000000\"> (c == enDash || c == emDash || c == horizontalBar ||<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c == <\/font><span>&#8216;-&#8216;<\/span><font color=\"#000000\">);<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">}<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>static<\/span><font color=\"#000000\"> <\/font><span>bool<\/span><font color=\"#000000\"> IsSingleQuote(<\/font><span>char<\/span><font color=\"#000000\"> c)<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">{<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">&nbsp;&nbsp;&nbsp; <\/font><span>return<\/span><font color=\"#000000\"> (c == quoteSingleLeft || c == quoteSingleRight ||<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c == quoteSingleBase || c == quoteReversed || c == <\/font><span>&#8216;\\&#8221;<\/span><font color=\"#000000\">);<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">}<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>static<\/span><font color=\"#000000\"> <\/font><span>bool<\/span><font color=\"#000000\"> IsDoubleQuote(<\/font><span>char<\/span><font color=\"#000000\"> c)<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">{<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">&nbsp;&nbsp;&nbsp; <\/font><span>return<\/span><font color=\"#000000\"> (c == <\/font><span>&#8216;&#8221;&#8216;<\/span><font color=\"#000000\"> || c == quoteDoubleLeft ||<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c == quoteDoubleRight || c == quoteLowDoubleLeft);<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">}<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span><font color=\"#000000\"> <\/font><span>static<\/span><font color=\"#000000\"> <\/font><span>bool<\/span><font color=\"#000000\"> IsQuote(<\/font><span>char<\/span><font color=\"#000000\"> c)<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">{<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">&nbsp;&nbsp;&nbsp; <\/font><span>return<\/span><font color=\"#000000\"> (IsSingleQuote(c) || IsDoubleQuote(c));<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span><font color=\"#000000\">}<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><font face=\"Times New Roman\" color=\"#000000\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><span>Of course it\u2019s not just Word that we want to support. We want to provide reasonable support for arbitrary applications (within the limitations of the console host for now) so if anyone sees anything we missed, please let me know. <\/span><\/p>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span>Now, for the trivia folks in the audience who want to know what an en is, from encarta:<\/span><\/p>\n<p class=\"MsoNormal\"><span>em dash (plural em dash\u00b7es) <br \/>noun&nbsp; <br \/>Definition: <br \/>long dash: in printing, a dash that is one em long<br \/>&nbsp;<br \/>en dash (plural en dash\u00b7es) <br \/>noun&nbsp; <br \/>Definition: <br \/>dash one en long: in printing, a dash that is one en in length <br \/>&nbsp;<br \/>en [ en ] (plural ens) <br \/>noun&nbsp; <br \/>Definition: <br \/>measure of printing width: a measure of printing width, half that of an em <\/span><\/p>\n<p class=\"MsoNormal\"><span>em [ em ] (plural ems) <br \/>noun&nbsp; <br \/>Definition: <br \/>1. variable measure of type: a unit of measurement of print size, equal to the point size of the typeface being used<br \/>2. printing&nbsp; <br \/>Same as&nbsp; pica<br \/>&nbsp;<br \/>[Late 18th century. Representing pronunciation of m because the letter is about this width] <\/span><\/p>\n<p><span><\/p>\n<p class=\"MsoNormal\">-bruce<\/p>\n<p class=\"MsoNormal\"><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span>Bruce Payette<\/span><\/p>\n<p class=\"MsoNormal\"><span>PowerShell Technical Lead<\/span><\/p>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span>PSMDTAG:FAQ:&nbsp;Can I cut-n-paste examples from WORD documents?<br \/>PSMDTAG:PARSER: (em dash, en dash, dash) handling<\/span><\/p>\n<p class=\"MsoNormal\"><\/span>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some people have noticed that you can paste examples out of Word documents directly into a PowerShell session. Given all of the typographic tricks that Word does, this is actually much harder than it sounds. Here\u2019s what we do. There&#8217;s a piece of code in the interpreter that takes each of the possible characters and [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[10,24],"class_list":["post-10401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-faq","tag-parser"],"acf":[],"blog_post_summary":"<p>Some people have noticed that you can paste examples out of Word documents directly into a PowerShell session. Given all of the typographic tricks that Word does, this is actually much harder than it sounds. Here\u2019s what we do. There&#8217;s a piece of code in the interpreter that takes each of the possible characters and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=10401"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10401\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=10401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=10401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=10401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}