{"id":86355,"date":"2019-09-25T13:00:39","date_gmt":"2019-09-25T21:00:39","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/scripting\/?p=86355"},"modified":"2019-09-30T07:39:34","modified_gmt":"2019-09-30T15:39:34","slug":"powertip-converting-a-here-string-to-an-array-in-one-line-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-converting-a-here-string-to-an-array-in-one-line-with-powershell\/","title":{"rendered":"PowerTip: Converting a Here-String to an Array in One Line with PowerShell"},"content":{"rendered":"<p><strong>Summary<\/strong>: Using the split method in a more powerful fashion to split an array based upon two line terminating types<\/p>\n<p><img decoding=\"async\" width=\"34\" height=\"34\" class=\"wp-image-86356\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/a-picture-containing-scissors-description-automat-3.jpeg\" alt=\"A picture containing scissors Description automatically generated\" \/><\/p>\n<p>Hey, Doctor Scripto. I was wondering if there was a more efficient way of converting a Here-String to an Array when there were multiple line termination options like Linefeed or Carriage Return and Linefeed?<\/p>\n<p><img decoding=\"async\" width=\"34\" height=\"34\" class=\"wp-image-86357\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-3.jpeg\" \/><\/p>\n<p>There most definitely is. You can pass multiple parameters to the split method. This example traps both!<\/p>\n<p><strong>$HereStringSample=@&#8217;\nBanana\nRaspberry\n&#8216;@<\/strong><\/p>\n<p><strong>$HereStringSample.<span>Split(@(&#8220;$([char][byte]10)&#8221;, &#8220;$([char][byte]10)&#8221;,&#8221;$([char][byte]13)&#8221;, [StringSplitOptions]::None))<\/span><\/strong><\/p>\n<p>PowerShell, Doctor Scripto, PowerTip, Paulo Morgado<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Using the split method in a more powerful fashion to split an array based upon two line terminating types Hey, Doctor Scripto. I was wondering if there was a more efficient way of converting a Here-String to an Array when there were multiple line termination options like Linefeed or Carriage Return and Linefeed? There [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1739,1738,639,687,685],"tags":[1740,2086,377,356,174],"class_list":["post-86355","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-doctor-scripto","category-powershell","category-powertip","category-regular-expressions","category-scripting-techniques","tag-doctor-scripto","tag-paulo-morgado","tag-powershell","tag-powertip","tag-regular-expressions"],"acf":[],"blog_post_summary":"<p>Summary: Using the split method in a more powerful fashion to split an array based upon two line terminating types Hey, Doctor Scripto. I was wondering if there was a more efficient way of converting a Here-String to an Array when there were multiple line termination options like Linefeed or Carriage Return and Linefeed? There [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=86355"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86355\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=86355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=86355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=86355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}