# Fortran Wiki scan

## 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.

## Standard

Fortran 95 and later, with kind argument Fortran 2003 and later

## Class

Elemental function

## Syntax

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

## Arguments

• 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.

## 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