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. | ||
Results: | The result type is default integer.
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.