SEARCH Function

Purpose

Returns the first position in a string where a character or bit of another string appears. You can also specify the location from which to start searching.

Syntax

SEARCH(x,y,z)

Parameters

x
An expression which pecifies 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

SEARCH returns the first position in the string x where a character or bit of the string y appears. The result is an unscaled real fixed binary value.If any of these two expressions is a null string, the result is zero. If y doesn't appear in x, the result is zero.

You can also specify the location from which to start searching with the expression z.

The SEARCH function can be used to find delimiters in a string of numbers.

Examples

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

    s = 'Newbury, England';
    i = search (s, 'ry');            /* i = 6, ‘r’ found starting from the left */

Restrictions

None.