Vector_lastIndexOf |
Homepage Containers |
Searches for the last occurrence, starting with startIndex, for which the specified function returns the search value, and returns the index for this element.
foundAt := Vector_lastIndexOf(VectorObject, searchValue, startIndex = 0, useFunction = "getValue", CaseSensitive = false)
| VectorObject | The Vector 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 last 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 index for the last 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 Vector_lastIndexOf(...) would be true if an element is found, and false otherwise.
If VectorObject 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 Vector_SlastIndexOf omitting the CaseSensitive parameter to perform a case-sensitive comparasion (==).
Index values start at 1 and "wrap".
Vector_indexOf, Vector_SlastIndexOf, Vector_regexLastIndexOf
Vector_findMatch, Vector_findLastMatch
Vector_findLastObject, Vector_lastUnset
;Creates a new Vector with the default parameters. myVector := Vector_new() ;Creates some String objects aString1 := String_new("Value1") aString2 := String_new("Value2") aString3 := String_new("Value1") ;Adds the Strings to myVector Vector_add(myVector, aString1) Vector_add(myVector, aString2) Vector_add(myVector, aString3) ;Searches for "Value1" (uses the default function, "getValue"). searchValue := "Value1" if foundAt := Vector_lastIndexOf(myVector, searchValue, 2) { ;foundAt contains the index for the element. MsgBox, % """" . searchValue . """ is found at index " foundAt "." } else { ;foundAt = 0 (i.e. not found) MsgBox, % "Search value was not found." }