Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Split an array of string and flatten into single array

$
0
0

I have a following array of strings

$array = @("asdf asdf","aaa ddd","cccc a","aaaa dd")

and I would like to split every element of that array by a new line and put the result into  array

So expected result should look as follows

@("asdf", "asdf", "aaa", "ddd", "cccc", "a", "aaaa", "dd")

I would like to avoid using nested foreach statement and preferably use some kind of SelectMany syntax

So far I've tried 

$result = $array | %{$_.Split([Environment]::NewLine)}  
$result = $array | Select-Object -ExpandProperty $_.Split([Environment]::NewLine)

but with no luck. Any thoughts?






Viewing all articles
Browse latest Browse all 21975

Trending Articles



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