# Turn a multi dimensional array into a string

## Recommended Posts

How do i turn a multi-dimensional array into a string from left to right, top to bottom, using a"|" to separate each value?

[center][/center][center]=][u][/u][/center][center][/center]

##### Share on other sites

How do i turn a multi-dimensional array into a string from left to right, top to bottom, using a"|" to separate each value?

```Dim \$names[3][3], \$str
\$names[0][0] = "x"
\$names[0][1] = "y"
\$names[0][2] = "z"
\$names[1][0] = "a"
\$names[1][1] = "b"
\$names[1][2] = "c"
\$names[2][0] = "d"
\$names[2][1] = "e"
\$names[2][2] = "f"

For \$i = 0 to UBound(\$names, 1)-1
For \$j = 0 to UBound(\$names, 2)-1
\$str &= \$names[\$i][\$j]
If \$j < UBound(\$names, 2)-1 Then \$str &= "|"
Next
If \$i < UBound(\$names, 1)-1 Then \$str &= "|"
Next

MsgBox(0, "", \$str)```

##### Share on other sites

Something like this, maybe ?

```Dim \$arr[\$a][\$b]

For \$i = 0 To \$a - 1
For \$j = 0 To \$b -1
\$string &= "|" & \$arr[\$i][\$j]
Next
Next

\$string = StringTrimLeft(\$string, 1)    ; remove extra "|" before first element```

Of course it is a matter of opinion/choice which dimension you choose to represent rows/columns,

so swap to taste ...

whim

##### Share on other sites

thanks for all your help, I know I have been asking a lot lately, But I am suffering from depression and can not think clearly.

[center][/center][center]=][u][/u][/center][center][/center]

## Create an account

Register a new account

×

• Wiki

• Back

• Git