SCAN(3) - [CHARACTER:SEARCH] Scan a string for the presence of a set of characters
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
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.
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.
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.
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.
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_scanResults:
> 2 > 6 > 0
Fortran 95 , with KIND argument - Fortran 2003
Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
Fortran intrinsic descriptions (license: MIT) @urbanjost
o ELEMENTAL: ADJUSTL(3), ADJUSTR(3), INDEX(3), VERIFY(3) o NONELEMENTAL: LEN_TRIM(3), LEN(3), REPEAT(3), TRIM(3)
Nemo Release 3.1 | scan (3fortran) | November 02, 2024 |