Jump to content

Looping over an array


Recommended Posts

Hey there,

I have made a string list delimited by "|" and each of those list items contains a sub list delimited by a "," like so:

$biglist = "circle1, circle2, circle3|box1,box2,box3"

$listArray = stringsplit($biglist, "|")

$item1 = stringsplit($listArray[1], ",")

soooo... $item1 would = "circle1"

All fine and good. Now what I want to do is do that for every item in the biglist.

My problem is I can't find out how to do a loop over the whole array, I don't see an arrayLen() type function... am I just missing it?

Alternatively, am I going about this the long hard way and missing an easier method?

Link to comment
Share on other sites

Ah crap your right, soon as I read your reply I remembered this part of the help file:

Returns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings.

:ph34r:

Link to comment
Share on other sites

You can also use the first item in the array of a stringsplit [0]

Ex:

$biglist = "circle1, circle2, circle3|box1,box2,box3"

$listArray = stringsplit($biglist, "|")
for $i= 1 to $listArray[0]
$item1 = stringsplit($listArray[$i], ",")
for $b= 1 to $item1[0]
msgbox(1,$listArray[$i],$item1[$b])
next
next

AutoIt3, the MACGYVER Pocket Knife for computers.

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...