FIND
Use the FIND script function to search a script array, and return the corresponding index position.
Syntax
FIND (script array, string [, start index] )
Parameters
-
FIND
Searches the script array -
Script array
Name of the script array to search -
String
String or number to search for
Format: string literal, number without quotation marks, or a script variable -
Start index
(Optional) Index from which to start the search
Format: number without quotation marks, or a script variable
Return Codes
- Index of the array in which the search key is found
- 0 if there is no search result
Notes:
- Searching for a Search key has the effect that a search is made for all script-array values starting with the index start position.
- The complete array is searched if you do not specify a start position, starting with index 1.
- A successful search returns the array index in which the text or number is found first. Use the next index of the previous result as the start position to continue the search for the remaining part of the array.
- Specify arrays with empty square brackets.
Tips:
- Use :DEFINE to create script arrays and declare the data type and size of the array.
- Set individual array elements and specify the index with the :SET statement.
- Use :FILL to store multiple values in an array at once.
For more information about script arrays, see Arrays.
Examples
The following example creates and initializes an array with VARA object values. The script searches for the string WIN in the complete array. The results are written in the activation report.
:DEFINE &array#, string, 5
:FILL &array#[] = GET_VAR(VARA.WIN, AGENTS)
:SET &search# = FIND(&array#[], "WIN", 1)
:WHILE &search# <> 0
:PRINT "WIN found at position &search#"
:SET &search# = &search# + 1
:SET &search# = FIND(&array#[], "WIN", &search#)
:ENDWHILE
See also: