FIND

Use the FIND script function to search a script array and return the index position of a matching element.

Notes:

  • A successful search returns the index of the first match. To continue searching the remaining array, use the next index after the previous result as the start index for the next call.
  • Use :DEFINE to create script arrays and declare their data type and size.
  • Use :SET to set individual array elements by index.
  • Use :FILL to populate an array with multiple values at once.
  • For more information about script arrays, see Arrays.

Syntax

FIND (Script array, String [, Start index])

Parameters

Parameter Description Format
Script array

Name of the script array to search. Specify with empty square brackets [].

n.a.
String

String or number to search for.

String literal, number without quotation marks, or script variable
Start index
(Optional)

Index position from which to start the search. If omitted, the search starts at index 1 and covers the entire array.

Default Value: 1

Number without quotation marks, or script variable

Return Codes

Return Value Condition
Index The index of the first array element in which the search value is found.
0 No match found.

Examples

The following example creates and populates an array with VARA object values, then searches the entire array for the string WIN and prints every matching index to 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