INDEXR Function

Purpose

Searches a string for a specified substring and returns a fixed binary integer value indicating its position.

Syntax

INDEXR(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.

Description

The INDEXR function searches a string, s, for a specified substring, c, and returns an integer value indicating the position of c within s. The search is done from the right end of s to the left. 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 rightmost character or bit (if s and c are bit strings) of the substring c. The result precision is Fixed Binary(15).

The third optional argument l must have a computational type and if it is used, the result precision is Fixed Binary(31,0). Its default value is LENGTH(s). If l is greater than 0 and less than LENGTH(s), the result is zero.

Examples

Example 1:

dcl s char (40) ;
dcl i fixed bin (15);

s = 'dmf plb cp js acb ltt dsa';
i = indexr(s, 'd');
put skip list (substr(s, i, 3));

will print

dsa

Example 2:

dcl s char (40) ;
dcl i fixed bin (15);

s = 'dmf plb cp js acb ltt dsa';
i = indexr(s, 'd');
put skip list (substr(s, i, 5));

will print


               	 

Restrictions

None.