Quantcast
Channel: Scripting Blog
Viewing all articles
Browse latest Browse all 2129

PowerTip: Converting a Here-String to an Array in One Line with PowerShell

$
0
0

Summary: Using the split method in a more powerful fashion to split an array based upon two line terminating types

A picture containing scissors Description automatically generated

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 most definitely is. You can pass multiple parameters to the split method. This example traps both!

$HereStringSample=@’
Banana
Raspberry
‘@

$HereStringSample.Split(@(“$([char][byte]10)”, “$([char][byte]10)”,”$([char][byte]13)”, [StringSplitOptions]::None))

PowerShell, Doctor Scripto, PowerTip, Paulo Morgado

The post PowerTip: Converting a Here-String to an Array in One Line with PowerShell appeared first on Scripting Blog.


Viewing all articles
Browse latest Browse all 2129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>