The INDEX function returns the starting position of a substring within a string.
Syntax
INDEX (string, substring [, back])
string is an INTENT(IN) scalar or array of type CHARACTER.
substring is an INTENT(IN) scalar or array of type CHARACTER.
back is an INTENT(IN) scalar of type LOGICAL.
The result is of type default INTEGER.
If back is absent or false, the result value is the position in string where the first instance of substring begins.
If back is true, the result value is the position number in string where the last instance of substring begins.
If substring is not found, or if string is shorter than substring, the result is zero.
If substring is of zero length, and back is absent or false, the result value is one.
If substring is of zero length, and back is true, the result value is LEN(string)+1.
Example
character(len=20) :: c1 = "Howdy There! ", & c2(3)=(/"To be or not to be ", & "Believe it or not ", & "I'll be there "/) character(len=2) :: s2(3)=(/"be", "Be", "ow"/) write(*,*) index(c1,"The") ! writes 7 write(*,*) index(c1,s2) ! writes 0 0 2 write(*,*) index(c2,"be") ! writes 4 0 6 write(*,*) index(c2,s2, back=.true.) ! writes 17 1 0