index(3f) - [FORTRAN:INTRINSIC:CHARACTER] Position of a substring within a string
Syntax
Description
Arguments
Return Value
Standard
Class
Example
See Also
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
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.
* 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.
* START The return value is of type INTEGER and of kind KIND. If KIND is absent, the return value is of default integer kind.
[[FORTRAN 77]] and later, with KIND argument [[Fortran 2003]] and later
[[Elemental function]]
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_indexExpected Results:
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 |