FIND

Script function: Searches a script array and returns the corresponding index.

Syntax

FIND (script array, string [, start index] )

Syntax

Description/Format

Script array

Name of the script array that should be searched.
Format: script variable

Search key String or number that should be searched.
Format: string literal, number without inverted commas, script variable
Start index Index from which the search should start.
Format: number without inverted commas, script variable

Return codes

Index of the array in which the search key was found.
0 = No search result

Comments

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 will be searched if no start position has been specified (starting with index 1). A successful search returns the array index in which the text or number could be found first. You can use the next index of the previous result as the start position to continue the search for the remaining part of the array. The script function FIND returns 0 if no results could be found.

Script arrays need to be specified with empty square brackets [].

Use :DEFINE to create script arrays; the data type and size are also determined during this process. Array fields to which no particular value has been assigned obtain the default value "" (data type: string) or 0 (numerical data types). Thus, the script function FIND is only useful if the array includes the corresponding values. You can set array elements individually and specify the index using :SET. The script statement :FILL can be used to store several different values to an array at the same time.

Examples

The example shown below creates and initializes an array with Variable object values. Afterwards, WIN will be searched in the complete array and all results will be written 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:

Script element Description

:FILL

Stores several values in a script array.

LENGTH Retrieves the size of a script array.