michaelslamet 33 Posted March 16, 2011 (edited) Hi, Let say I have a array. I want only array content that begin with XX and length less than 6. Example: current array is: $current_array[0] = "AB1234" $current_array[1] = "XX11" $current_array[2] = "XX1234567" $current_array[3] = "XX123" $current_array[4] = "XA1234" New array should be: $new_array[0] = "XX11" $new_array[1] = "XX123" which is begin with XX and less than 6 in length. Any build-in function to do this? Thanks a lot Edited March 17, 2011 by michaelslamet Share this post Link to post Share on other sites
hannes08 39 Posted March 16, 2011 Hi michaelslamet, I don't know any builtin function, you'll need to do it this way: $new_array = $current_array For $i = Ubound($new_array) -1 To 0 Step -1 If Stringleft($new_array[$i],2) <> "XX" Or StringLen($new_array[$i]) >= 6 Then _ArrayDelete($new_array,$i) EndIf Next Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Share this post Link to post Share on other sites
michaelslamet 33 Posted March 16, 2011 Thanks Hannes Why we should use descending for? Just wonder, instead of For $i = Ubound($new_array) -1 To 0 Step -1 can we use For $i = 1 to Ubound($new_array) - 1 ? Share this post Link to post Share on other sites
hannes08 39 Posted March 16, 2011 Hi michaelslamet, if you use _ArrayDelete() it decreases the indexes: $a[0] = 1 $a[1] = 2 $a[2] = 3 _ArrayDelete($a, 1) $a[0] = 1 $a[1] = 3 If you use this in a loop you will throw an exception like array out of bounds. That's why going backwards. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Share this post Link to post Share on other sites
michaelslamet 33 Posted March 17, 2011 ok, understand. Implement this into my code successfully. Thanks a lot, Hannes Share this post Link to post Share on other sites