Loading...
Searching...
No Matches
index

Definition

Locate the position of a substring.

This generic interface extends the intrinsic Fortran index function to support the fpx string type.

Supported combinations are:

  • index(string, string)
  • index(string, character(*))
  • index(character(*), string)

The optional argument back behaves exactly as in the intrinsic Fortran procedure:

  • if absent or .false., the first occurrence is returned;
  • if .true., the last occurrence is returned.

The function returns zero if the substring is not found.

Examples

String and character:

type(string) :: s
s = 'banana'
print *, index(s, 'na') ! 3
print *, index(s, 'xy') ! 0

String and string:

type(string) :: text
type(string) :: sub
text = 'banana'
sub = 'na'
print *, index(text, sub) ! 3

Search from the end:

type(string) :: s
s = 'banana'
print *, index(s, 'na', back=.true.) ! 5

Mixed usage:

type(string) :: sub
sub = 'ana'
print *, index('banana', sub) ! 2
Returns
Position of the matching substring, or zero if not found.

Definition at line 395 of file string.f90.


The documentation for this interface was generated from the following file: