Vesper
Vesper

Reputation: 18747

An easy way to output an array in a single line

I have an array in a line of $a=@(1,2,3,4,56). When I do Write-Debug $a I get an exception in a line of "Array is not a String". If I do $a | out-string | write-debug I get a list of values in a column. I can write a function that'll write an array in a row (or a string without newlines), but I'd like to know if I'm inventing a bicycle that exists in Powershell, so I can use an existing solution.

Is there a built in function or a not too fancy one-liner to display an array in a format similar to (1,2,3,4,56)?

Upvotes: 9

Views: 17058

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

Yes, using -join:

$a -join ','

Upvotes: 15

Related Questions