Jump to content

_ArrayLookup, returns elements containing a value.


Datenshi
 Share

Recommended Posts

Needed this so i put it together in 10min, someone might find it useful. If you're wondering what it does then read help for _ArrayFindAll. Basically returns an array of elements that contain a certain string.

iPartial = 1 means $vValue of "hello", will match byehellobye. Default is 0 is exact match, "hello" matches only "hello".

Func _ArrayLookup(Const ByRef $avArray, $vValue, $iStart = 0, $iEnd = 0,$iPartial = 0) ; Quickly searches an array for a specific value and return element if found.
    Local $iResSize = 0, $avSize = UBound($avArray) - 1
    If $iStart > $avSize Then Return SetError(2) ; out of bound
    Dim $avResult[$avSize]
    If $iEnd <> 0 And $iEnd <= $avSize Then $avSize = $iEnd ; If End param is valid set it.
    For $iIndex = $iStart To $avSize
        Switch $iPartial
            Case 0
            If StringInStr($avArray[$iIndex], $vValue) <> 0 Then ; allows partial match
            $avResult[$iResSize] = $iIndex
            $iResSize += 1
        EndIf
    Case 1
            If $avArray[$iIndex] = $vValue Then ; allows only exact match
            $avResult[$iResSize] = $iIndex
            $iResSize += 1
        EndIf
    Next
    If $iResSize = 0 Then Return SetError(1) ; nothing found
    ReDim $avResult[$iResSize]
    Return $avResult
EndFunc   ;==>_ArrayLookup
Edited by Datenshi
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...