Function reference
Finds the last position of a target string in a source string.

LastPos ( string1, string2, searchlength ) | Argument | Description | | string1 | The string in which you want to find string2. | | string2 | The string you want to find in string1. | |searchlength (optional) | A long that limits the search to the leftmost searchlength characters of the source string string1. The default is the entire string. |

Data type: Long
Returns a long whose value is the starting position of the last occurrence of string2 in string1 within the characters specified in searchlength. If string2 is not found in string1 or if searchlength is 0, LastPos returns 0. If any argument’s value is null, LastPos returns null.

The LastPos function is case sensitive. The entire target string must be found in the source string.

Example 1
This statement returns 6, because the position of the last occurrence of RU is position 6:
LastPos(‘BABE RUTH’, ‘RU’)

Example 2
This statement returns 3:
LastPos(‘BABE RUTH’, ‘B)

Example 3
This statement returns 0, because the case does not match:
LastPos(‘BABE RUTH’, ‘be’)

Example 4
This statement searches the leftmost 4 characters and returns 0, because the only occurrence of RU is after position 4:
LastPos(‘BABE RUTH’, ‘RU’, 2)

Last modified: 23 May 2021


Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment