POSITV: Finding the Beginning of a Variable Length Substring

How to:

The POSITV 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 4. If the substring is not in the parent string, the function returns the value 0. This is similar to POSIT; however, the lengths of its AnV parameters are based on the actual lengths of those parameters in comparison with two other parameters that specify their sizes.


Top of page

x
Syntax: How to Find the Beginning of a Variable Length Substring
POSITV(source_string, upper_limit, substring, sub_limit, output)

where:

source_string

Alphanumeric of type An or AnV

Is the source string that contains the substring whose position you want to find. If it is a field of AnV format, its length is taken from the length bytes stored in the field. If upper_limit is smaller than the actual length, the source string is truncated to this upper limit.

upper_limit

Integer

Is a limit for the length of the source string.

substring

Alphanumeric of type An or AnV

Is the substring whose position you want to find. If it is a field of type AnV, its length is taken from the length bytes stored in the field. If sub_limit is smaller than the actual length, the source string is truncated to this limit.

sub_limit

Integer

Is limit for the length of the substring.

output

Integer



Example: Finding the Starting Position of a Variable Length Pattern

POSITV finds the starting position of a comma in TITLEV, which would indicate a trailing definite or indefinite article in a movie title (such as ", THE" in SMURFS, THE). LENV is used to determine the length of title. The result is stored in a column with the format I4:

POSITV(TITLEV,LENV(TITLEV,'I4'), ',', 1,'I4')

For “SMURFS, THE”, the result is 7.

For “SHAGGY DOG, THE”, the result is 11.


iWay Software