Product SiteDocumentation Site

7.4.36. LASTPOS (Last Position)


>>-LASTPOS(needle,haystack-+---------------------------+--)----------------------><
                           +-,--+-------+--+---------+-+
                                +-start-+  +-,length-+

Returns the position of the last occurrence of one string, needle, in another, haystack. (See also Section 7.4.46, “POS (Position)”.) It returns 0 if needle is a null string or not found. By default, the search starts at the last character of haystack and scans backward to the beginning of the string. You can override this by specifying start, the point at which the backward scan starts and length, the range of characters to scan. The start must be a positive whole number and defaults to receiving_string~length if larger than that value or omitted. The length must be a non-negative whole number and defaults to start.
Here are some examples:

Example 7.49. Builtin function LASTPOS

LASTPOS(" ","abc def ghi")      ->    8
LASTPOS(" ","abcdefghi")        ->    0
LASTPOS("xy","efgxyz")          ->    4
LASTPOS(" ","abc def ghi",7)    ->    4
LASTPOS(" ","abc def ghi",7,3)  ->    0