SEARCHR Function

Purpose

Similar to the SEARCH function with a few differences.

Syntax

SEARCHR(x,y,z)

Parameters

x
An expression which specifies the string in which to search for a character or bit that appears in another string.
y
An expression where a character or bit appears.
z
An optional expression which specifies the location in the string x from which to start searching. It must have a computational type and is converted to Fixed Binary(31,0).

Description

SEARCHR does the same as SEARCH, i.e. it returns the first position in a string where a character or bit of another string appears. However, there are a few differences between them. With SEARCHR search is done from right to left and the default value for z is LENGTH(x).

Examples

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

    s = 'Newbury, England';
    i = searchr (s, 'ry');            /* i = 7, ‘y’ found starting from the right */

Restrictions

None.