[UP]


Manual Reference Pages  - index (3)

NAME

index(3f) - [FORTRAN:INTRINSIC:CHARACTER] Position of a substring within a string

SYNTAX

index(STRING, SUBSTRING [, BACK [, KIND]]) result(START)

     character(len=*),intent(in) :: STRING
     character(len=*),intent(in) :: SUBSTRING
     logical,intent(in),optional :: BACK
     integer,intent(in),optional :: KIND
     integer(kind=KIND)          :: START

DESCRIPTION

Returns the position of the start of the leftmost or rightmost occurrence of string SUBSTRING in STRING, counting from one. If SUBSTRING is not present in STRING, zero is returned.

ARGUMENTS

STRING string to be searched
SUBSTRING
  string to attempt to locate in STRING
BACK If the BACK argument is present and true, the return value is the start of the rightmost occurrence rather than the leftmost.
KIND An INTEGER initialization expression indicating the kind parameter of the result.

RETURN VALUE

START The return value is of type INTEGER and of kind KIND. If KIND is absent, the return value is of default integer kind.

STANDARD

[[FORTRAN 77]] and later, with KIND argument [[Fortran 2003]] and later

CLASS

[[Elemental function]]

EXAMPLE

Example program

   program demo_index
   implicit none
                                     !1234567890123456789012345678901234567890
   character(len=*),parameter :: str=’Search this string for this expression’
      write(*,*)index(str,’this’).eq.8,              &
                index(str,’this’,back=.true.).eq.24, &
                ! INDEX is case-sensitive
                index(str,’This’).eq.0
   end program demo_index

Expected Results:

   > T T T

SEE ALSO

Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
Elemental:
  adjustl(3), adjustr(3), index(3), len_trim(3), scan(3), verify(3)
Nonelemental:
  repeat(3), trim(3)


index (3) March 11, 2021
Generated by manServer 1.08 from 7a407d58-53c4-40c5-91d9-9a1f36012a6e using man macros.