tricky808 Posted April 21, 2005 Posted April 21, 2005 I have a list of values in an array. I want to break each of these values into a multidimensional array using the StringSplit function. Here is my test code: dim $testArray $testArray = StringSplit("one:1:won,two:2:too,three:3:tree,four:4:for,five:5",",") for $i = 1 to $testArray[0] $testArray[$i] = StringSplit($testArray[$i],":") for $t = 1 to UBound($testArray, 2)-1 MsgBox(0,"",$testArray[$i][$t]) Next Next The first StringSplit works just fine. The second StringSplit doesn't populate the second dimension of the arrayed variable. Has anyone done this before? Can this be done with StringSplit? TIA Aut viam inveniam aut faciam
steveR Posted April 22, 2005 Posted April 22, 2005 (edited) ;~ dim $testArray ;~ $testArray = StringSplit("one:1:won,two:2:too,three:3:tree,four:4:for,five:5",",") ;~ for $i = 1 to $testArray[0] ;~ ;~ $testArray[$i] = StringSplit($testArray[$i],":") ;~ ;~ for $t = 1 to UBound($testArray, 2)-1 ;~ MsgBox(0,"",$testArray[$i][$t]) ;~ Next ;~ Next dim $testArray dim $tmpArray dim $newArray[50][50] $testArray = StringSplit("one:1:won,two:2:too,three:3:tree,four:4:for,five:5", ",") for $i = 1 to $testArray[0] $tmpArray = StringSplit($testArray[$i], ":") for $t = 1 to UBound($tmpArray) -1 $newArray[$i][$t] = $tmpArray[$t] MsgBox(0, "", $i & " " & $t & @lf & $newArray[$i][$t]) Next Next Edited April 22, 2005 by steveR AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
tricky808 Posted April 22, 2005 Author Posted April 22, 2005 ;~ dim $testArray ;~ $testArray = StringSplit("one:1:won,two:2:too,three:3:tree,four:4:for,five:5",",") ;~ for $i = 1 to $testArray[0] ;~ ;~ $testArray[$i] = StringSplit($testArray[$i],":") ;~ ;~ for $t = 1 to UBound($testArray, 2)-1 ;~ MsgBox(0,"",$testArray[$i][$t]) ;~ Next ;~ Next dim $testArray dim $tmpArray dim $newArray[50][50] $testArray = StringSplit("one:1:won,two:2:too,three:3:tree,four:4:for,five:5", ",") for $i = 1 to $testArray[0] $tmpArray = StringSplit($testArray[$i], ":") for $t = 1 to UBound($tmpArray) -1 $newArray[$i][$t] = $tmpArray[$t] MsgBox(0, "", $i & " " & $t & @lf & $newArray[$i][$t]) Next Next<{POST_SNAPBACK}>That is a nice workaround... I appreciate the effort, but I was hoping StringSplit would do the trick. Thanks again. Aut viam inveniam aut faciam
PerryRaptor Posted April 24, 2005 Posted April 24, 2005 Hopefully this will help you...I used AutoIT version 3.1.1. Dim $lines,$Display, $NumCols $lines = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" ;--------------------------------------------------------------------- ;Lets convert a comma delimited string into a single dimension array ;--------------------------------------------------------------------- $Columns = StringSplit($lines, ",") $NumCols = $Columns[0] MsgBox(0,"Calculate # of Dimensions", "How many: " & $Columns[0]) ;--------------------------------------------------------------------- ;Lets build a multidimensional Array with enough columns ;--------------------------------------------------------------------- Dim $array[2][ $Columns[0] ] For $i = 1 To $Columns[0] $array[1][$i-1] = $Columns[$i] Next ;--------------------------------------------------------------------- ;Display comma delimited string to a multidimensional Array ;--------------------------------------------------------------------- For $j = 1 To $NumCols $Display = $Display & "array[1]["&String($j-1)&"]" & Chr(9) & " = " & chr(9) & $array[1][$j-1] & @CRLF Next MsgBox(4096, "Your Multidimensional Array",$Display) I think Multi-dimensional Arrays are the same thing as Excel Spreadsheets.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now