SCAN (The GNU Fortran Compiler)

### 8.246 `SCAN` — Scan a string for the presence of a set of characters ¶

Synopsis:

  `RESULT = SCAN(STRING, SET[, BACK [, KIND]])`

Description:

  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.

Class:

  Elemental function

Arguments:

  STRING | Shall be of type `CHARACTER`.
  SET | Shall be of type `CHARACTER`.
  BACK | (Optional) shall be of type `LOGICAL`.
  KIND | (Optional) A scalar `INTEGER` constant expression indicating the kind parameter of the result.

Return value:

  The return value is of type `INTEGER` and of kind KIND. If KIND is absent, the return value is of default integer kind.

Example:

      PROGRAM test_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

Standard:

  Fortran 90 and later, with KIND argument Fortran 2003 and later

See also:

  `INDEX` — Position of a substring within a string,
  `VERIFY` — Scan a string for characters not a given set