LF Fortran 95

SCAN Function

Description

The SCAN function scans a string for any one of a set of characters.

Syntax

SCAN (string, set [, back] )

Required Arguments

string is an INTENT(IN) scalar or array of type CHARACTER.

set is an INTENT(IN) scalar or array of type CHARACTER.

Optional Arguments

back is an INTENT(IN) scalar or array of type LOGICAL.

If more than one argument is an array, they must all have the same shape.

Result

The result is of type default INTEGER.

If back is absent, or if it is present with the value false, the value of the result is the position number of the leftmost character in string that is in set.

If back is present with the value true, the value of the result is the position number of the rightmost character in string that is in set.

If one or more arguments are arrays, the result is an array of the same shape. The value of each element of the resulting array is as if the scalar SCAN operation were performed on each respective element of the input arrays.

Example

character(len=12) :: c1="Howdy there!" character(len=6) :: c2(2)=(/"Howdy ","there!"/) character(len=3) :: c3(2)=(/"def","ghi"/) write(*,*) scan(c1,'def') ! writes 4 write(*,*) scan(c2,c3) ! writes 4 2 write(*,*) scan(c1,'def',back=.true.) ! writes 11 write(*,*) scan(c2,c3,(/.true.,.false./)) ! writes 4 2