Sign in to follow this  
Followers 0
Hooch

Looping over an array

6 posts in this topic

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?

Share this post


Link to post
Share on other sites



i am really new at v3 but $array[0] is the length of the array if i am not mistaken.

Share this post


Link to post
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:

Share this post


Link to post
Share on other sites

UBound() is the function you were looking for which returns the length of an array.

Share this post


Link to post
Share on other sites

Ah also good to know, thanks Valik

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0