Product Site

7.4.37. LASTPOS (Last Position)

Returns the position of the last occurrence of one string, needle, in another, haystack. 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 the length of haystack if larger than that value or omitted. The length must be a non-negative whole number and defaults to start.

See also POS built-in function.

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