scan(3f) - [FORTRAN:INTRINSIC:CHARACTER] Scan a string for the presence of a set of characters
Syntax
Description
Arguments
Return Value
Example
Standard
Class
See Also
result = scan(string, set[, back [, kind]])
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.
STRING - Shall be of type CHARACTER. SET - Shall be of type CHARACTER. BACK - (Optional) shall be of type LOGICAL. KIND - (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
The return value is of type INTEGER and of kind KIND. If KIND is absent, the return value is of default integer kind.
Sample program:
program demo_scan 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
[[Fortran 95]] and later, with KIND argument [[Fortran 2003]] and later
[[Elemental procedure|Elemental function]]
Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
Elemental: ADJUSTL, ADJUSTR, INDEX, LEN_TRIM, SCAN, VERIFY; Nonelemental: REPEAT, TRIM
scan (3) | March 19, 2019 |