INDEX intrinsic (The GNU Fortran Compiler)

### 8.155 `INDEX` — Position of a substring within a string ¶

Synopsis:

  `RESULT = INDEX(STRING, SUBSTRING [, BACK [, KIND]])`

Description:

  Returns the position of the start of the first occurrence of string SUBSTRING as a substring in STRING, counting from one. If SUBSTRING is not present in STRING, zero is returned. If the BACK argument is present and true, the return value is the start of the last occurrence rather than the first.

Class:

  Elemental function

Arguments:

  STRING | Shall be a scalar `CHARACTER`, with `INTENT(IN)`
  SUBSTRING | Shall be a scalar `CHARACTER`, with `INTENT(IN)`
  BACK | (Optional) Shall be a scalar `LOGICAL`, with `INTENT(IN)`
  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.

Specific names:

  Name | Argument | Return type | Standard
  --- | --- | --- | ---
  `INDEX(STRING,SUBSTRING)` | `CHARACTER` | `INTEGER(4)` | Fortran 77 and later

Standard:

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

See also:

  `SCAN` — Scan a string for the presence of a set of characters,
  `VERIFY` — Scan a string for characters not a given set