PowerShell for Windows Admins

Sep 28 2017   1:44PM GMT

Splitting multiline string

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Powershell

Saw an interesting question on splitting multiline string

If you get a set of strings

item1
item2
item3

emailed to you then you could put them in a text file and use Get-Content to read them into an array. The question was could you paste them into PowerShell and get the same effect.

Not sure if this is the easiest way but it works

PS> $x = @’
item1
item2
item3
‘@ -split “`n”

PS> $x.length
3

PS> $x[0]
item1

PS> $x[1]
item2

PS> $x[2]
item3

 

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: