Jump to content

[SOLVED] Array Question


Recommended Posts

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 by michaelslamet
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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