POSIT: Finding the Beginning of a Substring

How to:

The POSIT function finds the starting position of a substring within a larger string. For example, the starting position of the substring DUCT in the string PRODUCTION is four. If the substring is not in the parent string, the function returns the value 0.

There is a version of the POSIT function that is available only in the Maintain language. For information on this function, see POSIT: Finding the Beginning of a Substring (Maintain).


Top of page

x
Syntax: How to Find the Beginning of a Substring
POSIT(parent, inlength, substring, sublength, outfield)

where:

parent

Alphanumeric

Is the parent character string enclosed in single quotation marks, or a field or variable that contains the parent character string.

inlength

Integer

Is the length of the parent character string in characters, or a field that contains the length. If this argument is less than or equal to 0, the function returns a 0.

substring

Alphanumeric

Is the substring whose position you want to find. This can be the substring enclosed in single quotation marks, or the field that contains the string.

sublength

Integer

Is the length of substring. If this argument is less than or equal to 0, or if it is greater than inlength, the function returns a 0.

outfield

Integer

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.



Example: Finding the Position of a Letter

POSIT determines the position of the first capital letter I in LAST_NAME and stores the result in I_IN_NAME:

TABLE FILE EMPLOYEE
PRINT LAST_NAME AND COMPUTE
I_IN_NAME/I2 = POSIT(LAST_NAME, 15, 'I', 1, 'I2');
WHERE DEPARTMENT EQ 'PRODUCTION'
END

The output is:

LAST_NAME        I_IN_NAME
---------        ---------
STEVENS                  0
SMITH                    3
BANNING                  5
IRVING                   1
ROMANS                   0
MCKNIGHT                 5

Information Builders