1

I am exploring options for presenting multidimensional array in some specified format. Desired output is a single line string with elements within each dimension separated by specified character. For example:

$foo = @(@("A","B","C"),@("1","2","3"))
$bar = @()

foreach ($i in $foo)
{
    $bar += $i -Join ", "
}

$bar -join "; "

Produces desired output. When number of dimensions in the array grows, or is variable within the nested elements, this approach becomes cumbersome.

I am wondering if exists some Powershell magic to assist with this task. Ideally, something like:

$foo[([] -join ", ")] -join "; "

And perhaps a solution that will scale well for more complex array configurations.

Thoughts?

1 Answer 1

4

this way?

$foo = @(@("A","B","C"),@("1","2","3"))

($foo | % { $_ -join ',' }) -join '; '
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.