Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

SCAN Function

Elemental Intrinsic Function (Generic): Scans a string for any character in a set of characters.

result = SCAN (string, set [, back] [, kind])

string

(Input) Must be of type character.

set

(Input) Must be of type character with the same kind parameter as string.

back

(Input; optional) Must be of type logical.

kind

(Input; optional) Must be a scalar integer constant expression.

Results

The result type is integer. If kind is present, the kind parameter of the result is that specified by kind; otherwise, the kind parameter of the result is that of default integer. If the processor cannot represent the result value in the kind of the result, the result is undefined.

If back is omitted (or is present with the value false) and string has 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 string has 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.

If no character of string is in set or the length of string or set is zero, the value of the result is zero.

The setting of compiler options specifying integer size can affect this function.

Example

SCAN ('ASTRING', 'ST') has the value 2.

SCAN ('ASTRING', 'ST', BACK=.TRUE.) has the value 3.

SCAN ('ASTRING', 'CD') has the value zero.

The following shows another example:

 INTEGER i
 INTEGER array(2)
 i = SCAN ('FORTRAN', 'TR')                 ! returns 3
 i = SCAN ('FORTRAN', 'TR', BACK = .TRUE.)  ! returns 5
 i = SCAN ('FORTRAN', 'GHA')                ! returns 6
 i = SCAN ('FORTRAN', 'ora')                ! returns 0
 array = SCAN ((/'FORTRAN','VISUALC'/),(/'A', 'A'/))
                                        ! returns (6, 5)

 ! Note that when using SCAN with arrays, the string
 ! elements must be the same length. When using string
 ! constants, blank pad to make strings the same length.
 ! For example:

 array = SCAN ((/'FORTRAN','MASM '/),(/'A', 'A'/))
                                        ! returns (6, 2)
 END

See Also