Thursday, September 13, 2012

INDEX

INDEX returns the starting position of a substring within a string.
INDEX(STRING,SUBSTRING,BACK) 

EX:
1. INDEX('FORTRAN', 'R') has the value 3  
2. INDEX('FORTRAN', 'R',BACK=TRUE) has the value 5  
BACK is an optional parameter/argument.

Case (i): If BACK is absent or present with the value .FALSE., the result is the minimum positive value of I such that STRING (I : I + LEN (SUBSTRING) - 1) = SUBSTRING or zero if there is no such value. Zero is returned if LEN (STRING) < LEN (SUBSTRING). One is returned if LEN (SUBSTRING) = 0.

Case (ii): If BACK is present with the value .TRUE., the result is the maximum value of I less than or equal to LEN (STRING) - LEN (SUBSTRING) + 1, such that STRING (I : I + LEN (SUBSTRING) - 1) =  SUBSTRING or zero if there is no such value. Zero is returned if LEN (STRING) < LEN (SUBSTRING) and LEN (STRING) + 1 is returned if LEN (SUBSTRING) = 0.