Rocket® Enterprise Developer (formerly a product of Micro Focus or formerly a product of Open Text) documentation, created before Rocket Software acquired certain products from OpenText, may include outdated references to "Micro Focus" or "OpenText", both of which are trademarks of OpenText or its affiliates. Rocket Software is not affiliated with Micro Focus or OpenText and has since rebranded these products as Rocket® products. You may also encounter outdated links in this documentation. If you do, please contact Rocket Support (support@rocketsoftware.com) for assistance.
INDEX Function
Purpose
Searches a string for a specified substring and returns a fixed binary integer value indicating its position.
Syntax
INDEX(s,c,l)
Parameters
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.
Examples
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
Restrictions
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.
lspecifies 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 precision of the result is determined by the
-bifpreccompiler option.The third optional argument
lmust have a computational type and if it is used, the result precision is Fixed Binary(31,0). Iflis less than 1 or is greater than length(s), the result is zero.