Searches a string for a specified substring and returns a fixed binary integer value indicating its position.
INDEX(s,c,l)
s and c are both either character or bit strings, and c may be a substring of s. l is a third optional parameter which specifies the location in s from which to start searching.
Example of INDEX(s,c):
dcl s char (40) ; dcl i fixed bin (15); s = 'dmf plb cp js acb ltt dsa'; i = index(s, 'd'); put skip list (substr(s, i, 3));
will print:
dmf
Example of INDEX(s,c,l):
dcl s char (40) ; dcl i fixed bin (15); s = 'dmf plb cp js acb ltt dsa'; i = index(s, 'd', 5); put skip list (substr(s, i, 3));
will print:
dsa
None.
Description
The INDEX function searches a string, s, for a specified substring, c, and returns an integer value indicating the position of c within s. l specifies the location in the string from which the search begins.
If either s or c is a null string, the result is zero. If the substring c is not contained within s, the result is zero; otherwise, the result is an integer indicating the position within s of the leftmost character or bit (if s and c are bit strings) of the substring c. The result precision is Fixed Binary(15).
l must have a computational type and is converted to Fixed Binary(31,0). If l is less than 1 or is greater than length(s), the result is zero.