NET/MASTER Network Control Language (NCL) Reference Manual

POS
Built-in Functions
4–66 106126 Tandem Computers Incorporated
POS The POS built-in function returns the first location of a substring within a string,
beginning its search either at the first character of the string or at an optional specified
starting character position. The value returned is the character position at which the
substring starts. If the substring is not found, 0 (zero) is returned.
POS(
needle
,
haystack
[,
start
] )
needle
specifies the substring to search for.
haystack
specifies the string to be searched.
start
specifies the starting position for the search. If not specified, the search begins at
character position 1. If
start
specifies a position beyond the end of
haystack
, 0
(zero) is returned. This operand must be a positive whole number.
Considerations
If either
needle
or
haystack
is null, 0 (zero) is returned.
See also LASTPOS, which locates the last occurrence of a substring within a string.
This is the reverse of the POS built-in function.
Examples
In the following example, the string “DAY” is found within the string “MONDAY”.
The search begins at character position 1. The result is 4:
&A = DAY
&B = MONDAY
&RESULT = POS(&A,&B)
In the following example, the string “L” is found at position 17 within the string “THE
DATE IS APRIL 2”. The search begins at character position 1. The result is 17:
SAY POS(L,THE DATE IS APRIL 2,)
In the following example, the string “L” is found within the string “LAST DATE IS
APRIL 2”. The search begins at character position 4. The result is 18:
&A = L
&B = LAST DATE IS APRIL 2
&C = 4
&RESULT = POS(&A,&B,&C)
In the previous example, if the starting position is omitted, the result is 1.