index(3I)
INDEX - Determines the starting location of a character substring in a string
As shipped in IRIX 6.5.30. Last changed in IRIX 6.5.19.
NAME INDEX - Determines the starting location of a character substring in a string SYNOPSIS INDEX ([STRING=]string, [SUBSTRING=]substring [,[BACK=]back]) STANDARDS Fortran 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 with a value of true, the search begins at the end of string. This argument is not accepted by the MIPSpro Fortran 77 compiler. 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') yields 3. Example 2: INDEX('FORTRAN','R',BACK=.TRUE.) yields 5. Example 3: The following program returns the index I=10 for the substring SUPERCOMPUTER: PROGRAM INDEX1 CHARACTER*22 A CHARACTER*13 B A = 'CRAY T90 SUPERCOMPUTER' B = 'SUPERCOMPUTER' I = INDEX(A,B) PRINT *, I STOP END