Visible to Intel only — GUID: GUID-9DDC6436-A763-4492-923F-10648F43ADD0
Visible to Intel only — GUID: GUID-9DDC6436-A763-4492-923F-10648F43ADD0
INDEX
Elemental Intrinsic Function (Generic): Returns the starting position of a substring within a string.
result = INDEX (string, substring [,back] [, kind])
string |
(Input) Must be of type character. |
substring |
(Input) Must be of type character. |
back |
(Input; optional) Must be of type logical. |
kind |
(Input; optional) Must be a scalar integer constant 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 |
---|---|---|
CHARACTER |
INTEGER(1) |
|
CHARACTER |
INTEGER(2) |
|
INDEX 1 |
CHARACTER |
INTEGER(4) |
CHARACTER |
INTEGER(8) |
|
1The setting of compiler options specifying integer size can affect this function. |
Example
INDEX ('FORTRAN', 'O', BACK = .TRUE.) has the value 2.
INDEX ('XXXX', " ", BACK = .TRUE.) has the value 5.
The following shows another example:
I = INDEX('banana','an', BACK = .TRUE.) ! returns 4
I = INDEX('banana', 'an') ! returns 2