FINDSTR Statement
Locates a substring within a dynamic array element.
Syntax
FINDSTR substring IN dynArray{,occurrence} SETTING attrVar{,valVar{,subvalVar}} [THEN statement(s) | ELSE statement(s)]
Syntax Elements
substring An expression that evaluates to the substring to be located.
dynArray The dynamic array to be searched.
occurrence An integer specifying the required occurrence of substring.
If occurrence is not specified, it defaults to 1.
attrVar A variable that is set to the attribute position where the element is found.
valVar A variable that is set to the value position where the element is found.
subvalVar A variable that is set to the subvalue position where the element is found.
statement(s)Either a THEN or ELSE clause (or both). A statement must be included. The THEN clause is executed if FINDSTR is successful; otherwise the ELSE clause is executed.
If the ELSE clause is taken, variables attrVar, valVar, and subvalVar do not change.
Operation
FINDSTR returns the attribute and, if specified, the value and subvalue in which the element is found.
Case Insensitivity
If data case insensitive mode is selected (see Case Sensitivity), case is ignored when searching dynArray for substring.
Examples
ARRAYX = "ALABAMA":@AM:"CALIFORNIA":@AM:"MINNESOTA" FINDSTR "CA" IN ARRAYX,1 SETTING Y ELSE PRINT "NO 'CA'"; STOP
Finds the attribute (2) containing substring value CA in dynamic array ARRAYX. Sets Y to a number indicating the position of that attribute, in this case Y=2. Prints an error message if not found.
OPEN "FILE1" TO FILE ELSE PRINT "CANNOT OPEN"; G 10 READ NUM FROM FIL,"1" ELSE PRINT "CANNOT READ"; G 20 FINDSTR 33 IN NUM,1 SETTING K ELSE PRINT "NOT FOUND"; STOP PRINT K
Searches for substring 33 in NUM, item 1 and prints a number representing the location in array NUM where 33 occurs.