seesoe Posted March 2, 2009 Posted March 2, 2009 hello, i have data coming into my script that is dynamic <x#xx> let say $item holds that string, (string example - <5#23><2#24><5#25>) how can i create a loop that will run the function done($qty,$id) for each set of <> that is in the string?
qazwsx Posted March 2, 2009 Posted March 2, 2009 Use string split to get an array. Then use a for loop and the array.length attribute. Try to use "" around strings so it is clearer.
seesoe Posted March 2, 2009 Author Posted March 2, 2009 (edited) can you explain that a little bit more please i found this in the help file under for but i don't get it For $i = 5 to 1 Step -1 MsgBox(0, "Count down!", $i) Next i found StringRegExp, that looks like something i should use, how do i use it? Edited March 2, 2009 by seesoe
qazwsx Posted March 2, 2009 Posted March 2, 2009 The for loops adds the step (in this case -1) to the variable (in this case $i) each iteration. If no step is specified 1 is used.
seesoe Posted March 2, 2009 Author Posted March 2, 2009 so the stopping var in this case would be how much elements are in the array, so wheres array.length from?
seesoe Posted March 2, 2009 Author Posted March 2, 2009 $list_1 = "<2#4>,<4#5>" $list_2 = StringSplit($list_1,",") $list_3 = StringTrimLeft($list_2[1],1) $list = StringTrimRight($list_3,1) $item = StringSplit($list,"#") done($item[1],$item[2]) but this of course will only do the first set of <> how can i make the FOR do it for how ever much sets of <> there are?
CrewXp Posted March 2, 2009 Posted March 2, 2009 gaz was telling you to use a for loop. Like this: $list_1 = "<2#4>,<4#5>,<1#5>,<2#5>" $list_2 = StringSplit($list_1,",") For $i=1 To $list_2[0] $list_3 = StringTrimLeft($list_2[$i],1) $list = StringTrimRight($list_3,1) $item = StringSplit($list,"#") done($item[1],$item[2]) Next
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