NET/MASTER Network Control Language (NCL) Reference Manual

LASTPOS
Built-in Functions
4–48 106126 Tandem Computers Incorporated
LASTPOS The LASTPOS built-in function locates the last occurrence of a substring within a
string. The search starts at the last character of the string and scans backwards, unless
you specify an optional starting position. The value returned is the character position
of the substring within the string being searched. 0 (zero) is returned if the substring
does not exist.
LASTPOS(
needle
,
haystack
[,
start
]
)
needle
specifies the substring to be searched for.
haystack
specifies the string to be searched.
start
specifies the starting character position for the search. If start is not specified, or
if it specifies a character position beyond the end of
haystack
, the search begins
at the last character position of
haystack
. This operand must be a positive whole
number.
Considerations
If either
needle
or
haystack
is null, 0 (zero) is returned.
See also POS, which returns the location of a substring within a string.
Examples
In the following example, NCL searches the string “AAABBBCCCABC” for the
character “C”:
ASAX: PROCEDURE
&RESULT = LASTPOS(C,AAABBBCCCABC)
SAY THE RESULT IS &RESULT
END ASAX
In the previous example, the result 12 is displayed, which is the position of the last
occurrence of the character “C”.
In the following example, NCL searches the string “abc def ghi” for a space. The last
occurrence of a space is found at character position 8:
SAY LASTPOS(" ",abc def ghi)
In the following example, NCL searches the string “abcdefgh ” for a space. The last
occurrence of a space is found at character position 9:
SAY LASTPOS(" ","abcdefgh ")