Array_findMatch |
Homepage Containers |
Searches for the first occurrence, starting with startIndex, for which the specified function returns the search value, and returns the address for this element.
foundAt := Array_findMatch(ArrayObject, searchValue, startIndex = 1, useFunction = "getValue", CaseSensitive = false)
| ArrayObject | The Array object to use for the current operation. |
| searchValue | The search value to test against. |
| startIndex | The index to start searching from. If omitted, the search starts with the first item. |
| useFunction |
Function whose return is compared. The actual function called is %ClassName%_%useFunction%, with ClassName the class name for the current iteration's object. If useFunction is the empty string, no function is called, and the object itself is compared. |
| CaseSensitive | If omitted or false, the seach is not case sensitive (the method of insensitivity depends on StringCaseSense); otherwise, the case must match exactly. |
The address for the first matching element, starting with startIndex.
If there is no such element, the function returns 0.
The function's return can be used as a quasi-boolean value; the statement if Array_findMatch(...) would be true if an element is found, and false otherwise.
If ArrayObject is NULL (0 or blank), the empty string is returned, to indicate an error.
If an element is unset and useFunction is not the empty string, it will be skipped during the search.
By default, comparisons for equality are made using the case-insensitive equals (=). Either specify CaseSensitive to be true, or call Array_SfindMatch omitting the CaseSensitive parameter to perform a case-sensitive comparasion (==).
Index values start at 1 and "wrap".
Array_indexOf, Array_lastIndexOf, Array_regexIndexOf
Array_findLastMatch, Array_SfindMatch
Array_findObject, Array_firstUnset
;Creates a new Array (of length 10). myArray := Array_new(10) ;Creates some String objects aString1 := String_new("Value1") aString2 := String_new("Value2") aString3 := String_new("Value1") ;Adds the Strings to myArray Array_set(myArray, 1, aString1) Array_set(myArray, 2, aString2) Array_set(myArray, 3, aString3) ;Searches for "Value1" (uses the default function, "getValue"). searchValue := "Value1" if ClassObject := Array_findMatch(myArray, searchValue, 2) { ;ClassObject contains the address for the element. MsgBox, % """" . searchValue . """ is found in object " ClassObject ".`n" . "aString1: " . aString1 . "`n" . "aString2: " . aString2 . "`n" . "aString3: " . aString3 } else { ;ClassObject = 0 (i.e. not found) MsgBox, % "No object matches the specified search value." }