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')
print *, index(s, 'xy')
String and string:
type(string) :: text
type(string) :: sub
text = 'banana'
sub = 'na'
print *, index(text, sub)
Search from the end:
type(string) :: s
s = 'banana'
print *, index(s, 'na', back=.true.)
Mixed usage:
type(string) :: sub
sub = 'ana'
print *, index('banana', sub)
- Returns
- Position of the matching substring, or zero if not found.
Definition at line 395 of file string.f90.