9.3.69 INDEX (STRING, SUBSTRING [, BACK] [, KIND])

Description:  Returns the starting position of a substring within a string.  
Class:  Elemental function; Generic 
Arguments:  STRING Must be of type character. 
  SUBSTRING Must be of type character. 
  BACK (opt) Must be of type logical. 
  KIND (opt) Must be a scalar integer initialization expression.  
Results:  The result is of type integer. If KIND is present, the kind parameter of the result is that specified by KIND; otherwise, the kind parameter of the result is that of default integer. If the processor cannot represent the result value in the kind of the result, the result is undefined.

If BACK does not appear (or appears with the value false), the value returned is the minimum value of I such that STRING (I : I + LEN (SUBSTRING) - 1) = SUBSTRING (or zero if there is no such value). If LEN (STRING) < LEN (SUBSTRING), zero is returned. If LEN (SUBSTRING) = zero, 1 is returned.

If BACK appears with the value true, the value returned is the maximum value of I such that STRING (I : I + LEN (SUBSTRING) - 1) = SUBSTRING (or zero if there is no such value). If LEN(STRING) < LEN (SUBSTRING), zero is returned. If LEN (SUBSTRING) = zero, LEN (STRING) + 1 is returned. 

Specific Name  Argument Type  Result Type 
INDEX  CHARACTER  INTEGER(4) 
  CHARACTER  INTEGER(8) 

Examples

INDEX ('FORTRAN', 'O', BACK = .TRUE.) has the value 2.

INDEX ('XXXX', " ", BACK = .TRUE.) has the value 5.


Previous Page Next Page Table of Contents