Jump to content

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?

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)
Link to comment
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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...