INDEX(3I) Last changed: 1-6-98
NAMEINDEX - Determines the starting location of a character substring in a
string
SYNOPSISINDEX ([STRING=]string, [SUBSTRING=]substring [,[BACK=]back])
IMPLEMENTATION
UNICOS, UNICOS/mk, and IRIX systems
STANDARDS
Fortran 90
DESCRIPTION
The INDEX intrinsic function returns the starting position of a
substring within a string from either the right or left end of the
string. It accepts the following arguments:
string Must be of type character.
substring Must be of type character.
back Must be of type logical. If omitted, a value of false is
assumed. If present, the search begins at the end of
string.
INDEX is an elemental function. The name of this intrinsic can be
passed as an argument.
NOTES
When the INDEX intrinsic function is passed as an actual argument, it
must be called with only the first two arguments in the routine that
calls the passed-in function.
RETURN VALUES
The back argument can affect the return value as follows:
* If back is absent or is present with the value FALSE, the INDEX
search is relative to the left end of string. The result is the
minimum positive value of i, as follows:
string ( i : i + LEN( substring ) - 1 ) = substring
If the length of substring is 0, a value of 1 is returned.
* If back is present with the value TRUE, the INDEX search is relative
to the right end of string. The result is the maximum positive
value of the following:
i <= LEN( string ) - LEN( substring ) + 1
In the preceding equation, substring is as follows:
string ( i : i + LEN( substring ) - 1 ) = substring
If the length of substring is 0, the value returned is as follows:
LEN( string ) + 1.
If substring occurs more than once in string, INDEX returns the index
to the first occurrence.
The return value is 0 if substring is not located within string.
The return value is 0 if the length of string is less than the length
of substring.
EXAMPLES
Example 1: INDEX('FORTRAN','R') has the value 3.
Example 2: INDEX('FORTRAN','R',BACK=.TRUE.) has the value 5.
Example 3: The following program returns the index I=11 for the
substring SUPERCOMPUTER:
PROGRAM INDEX1
CHARACTER*23 A
CHARACTER*13 B
A = 'CRAY T90 SUPERCOMPUTER'
B = 'SUPERCOMPUTER'
I = INDEX(A,B)
PRINT *, I
STOP
END
SEE ALSO
Intrinsic Procedures Reference Manual, publication SR-2138, for the
printed version of this man page.