Jump to content

Arrays...


Aceguy
 Share

Recommended Posts

i have $array_a :-

$array_a[1] = a

$array_a[2] = b

$array_a[3] = c

$array_a[4] = d

$array_a[5] = e

and $array_b :

$array_b[1] = b

$array_b[2] = d

$array_b[3] = e

i want to exctract $array_b FROM $array_a

so the results will be :-

$array_a[1] = a

$array_a[2] = c

Hope this makes sense, thanks

Link to comment
Share on other sites

#include <Array.au3>

Dim $array_a[5]
$array_a[0] = "a"
$array_a[1] = "b"
$array_a[2] = "c"
$array_a[3] = "d"
$array_a[4] = "e"

Dim $array_b[3]
$array_b[0] = "b"
$array_b[1] = "d"
$array_b[2] = "e"

Dim $array_c = _ArrayExtract($array_a, $array_B)
_ArrayDisplay($array_c)

Func _ArrayExtract($Array1, $Array2)
    Dim $Array3[1], $Found
    For $i = 0 To UBound($Array1)-1
        $Found = False
        For $j = 0 To UBound($Array2)-1
            If $Array1[$i] == $Array2[$j] Then
                $Found = True
            EndIf
        Next
        If Not $Found Then
            ReDim $Array3[UBound($Array3)+1]
            $Array3[0] += 1
            $Array3[UBound($Array3)-1] = $Array1[$i]
        EndIf
    Next
    Return $Array3
EndFunc

Couldn't think of a better name for it, but it does what you want. It returns arrays like StringSplit() does, [0] element is the count of the rest of the items.

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