Manual Reference Pages  - scan (3fortran)

NAME

SCAN(3) - [CHARACTER:SEARCH] Scan a string for the presence of a set of characters

SYNOPSIS

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

         elemental integer(kind=KIND) function scan(string,set,back,kind)

character(len=*,kind=**),intent(in) :: string character(len=*,kind=**),intent(in) :: set logical,intent(in),optional :: back integer,intent(in),optional :: kind

CHARACTERISTICS

o STRING is a character string of any kind
o SET must be a character string with the same kind as STRING
o BACK is a logical
o KIND is a scalar integer constant expression
o the result is an integer with the kind specified by KIND. If KIND is not present the result is a default integer.

DESCRIPTION

SCAN(3) scans a STRING for any of the characters in a SET of characters.

If BACK is either absent or equals .false., this function returns the position of the leftmost character of STRING that is in SET. If BACK equals .true., the rightmost position is returned. If no character of SET is found in STRING, the result is zero.

OPTIONS

o STRING : the string to be scanned
o SET : the set of characters which will be matched
o BACK : if .true. the position of the rightmost character matched is returned, instead of the leftmost.
o KIND : the kind of the returned value is the same as KIND if present. Otherwise a default integer kind is returned.

RESULT

If BACK is absent or is present with the 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.

The value of the result is zero if no character of STRING is in SET or if the length of STRING or SET is zero.

EXAMPLES

Sample program:

    program demo_scan
    implicit none
       write(*,*) scan("fortran", "ao")          ! 2, found ’o’
       write(*,*) scan("fortran", "ao", .true.)  ! 6, found ’a’
       write(*,*) scan("fortran", "c++")         ! 0, found none
    end program demo_scan

Results:

     >            2
     >            6
     >            0

STANDARD

Fortran 95 , with KIND argument - Fortran 2003

SEE ALSO

Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
o ELEMENTAL: ADJUSTL(3), ADJUSTR(3), INDEX(3), VERIFY(3)
o NONELEMENTAL: LEN_TRIM(3), LEN(3), REPEAT(3), TRIM(3)
fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 scan (3fortran) April 28, 2024
Generated by manServer 1.08 from 9d647e7c-d0f6-4594-a6ef-4621b80200f8 using man macros.