scan

Date:

02-06-2023

NAME

SCAN - Scans a string for any one of the characters in a set of characters

SYNOPSIS

SCAN ([STRING=]string, [SET=]set [,[BACK=]back, [KIND=]kind])

STANDARDS

Fortran

DESCRIPTION

The SCAN intrinsic function scans string and returns the position of the first character in string that matches any characters in set. It accepts the following arguments:

string

Must be of type character.

set

Must be of type character.

back

Must be of type logical. If back is omitted, a value of false is assumed.

kind

Determines the kind type parameter of the return result. This argument must be a scalar integer initialization expression. See the RETURN VALUES section for more information.

SCAN is an elemental function. The name of this intrinsic cannot be passed as an argument.

RETURN VALUES

The return result is of type INTEGER and its kind type parameter is dependent on the kind argument. If the kind argument is not passed, the kind type parameter of result is the same as that of the default integer type; otherwise it is of the kind type parameter specified by the kind argument.

SCAN returns the character position of the first character in string that matches any characters in set. The result is a default integer.

If back is absent or present with value false and if string contains at least one character that is in set, the value of the result is the position of the leftmost character of string that is in set.

If back is present with the value true and if string contains at least one character that is in set, the value of the result is the position of the rightmost character of string that is in set.

SCAN returns zero if no character in string is in set or if the length of string is zero.

EXAMPLES

Example 1: The statement SCAN(‘FORTRAN’,’TR’) yields 3.

Example 2: The statement SCAN(‘FORTRAN’,’TR’,BACK=.TRUE., KIND=4) yields 5.

Example 3: The statement SCAN(‘FORTRAN’,’BCD’) yields 0