I want to output a formated string to console. I have one string variable and one string array variable.
When I do this:
$arr = "aaa","bbb"
"test {0} + {1}" -f "first",$arr
The output is this:
test first + System.Object[]
But I need output to be:
test first + aaa,bbb
Or something similar…
Several options:
Join the array first, so you don’t rely on the default
ToString()implementation (which just prints the class name):Use string interpolation:
You can change the delimiter used by setting
$OFS, which by default is a space:You can get the same result (including the note about
$OFS) withThis forces the array to be converted into a single string first, too.