[UP]


Manual Reference Pages  - index (3)

NAME

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

CONTENTS

Syntax
Description
Arguments
Return Value
Standard
Class
Example
See Also

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
                                     !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, ADJUSTR, INDEX, LEN_TRIM, SCAN, VERIFY;
Nonelemental:
  REPEAT, TRIM


index (3) March 18, 2019
Generated by manServer 1.08 from 959f872e-b0c2-461b-949e-b7274a216337 using man macros.