scan() Function

The scan() function searches through a specified str.exp for the first occurrence of up to three user-definable characters specified by search.delimiters in addition to the system delimiters value, subvalue, and attribute.

Syntax

scan(str.exp, search.delimiters)

Parameter(s)

str.exp

Specifies the string to search.

search.delimiters

Specifies up to three user-definable characters to be searched for in addition to the system delimiters value, subvalue, and attribute. The user-defined characters must be separated by a system delimiter (’ " \).

Description

If the delimiter is found, scan returns the numeric position where the occurrence was found.

If the specified search delimiters or any system delimiters are not found, 0 is returned.

If no match is found the result is 0.

NOTE

To use the scan() function, it is necessary to use a nondefault compiler options setting. Inserting the line $options ext at the beginning of the source item accomplishes this.

Example(s)

This returns the value, 5, to the variable d.position, because the first occurrence of either \’\ or \"\ is found in the fifth position of the string.

String = \The "first" or ’second’ name.\

d.position = scan(string,\’\:@am:\"\)

If ans is either an a, b, or c, the loop is terminated. Notice that a null value for ans results in a 0 from the scan() function.

loop

input ans,1

until scan(’abc’,ans) do repeat

See Also

$options Statement, BASIC Functions, Statements and Functions