See Also: String Functions, Pos, Left, Length, Mid, Right
Returns the ordinal position in code points of the last occurrence from the left of a substring in a host string or 0 (zero) if the substring is not found.
(RightPos( {sub-string}, {host-string} [, {StartingPosition}] [, {length} ] ))
Where:
{sub-string} is the string value that RightPos searches for in {host-string}.
{host-string} is the string value RightPos searches for an occurrence of {sub-string} in.
{StartingPosition} (optional)
specifies the starting (left-most) position in {host-string} where
the search is to begin. The position is in code points, 1-based, where
the first position in {host-string} is 1.
If less than 1, the function fails and returns 0. If greater than last
valid position in range, it is adjusted to the last valid position.
{length} (optional) specifies
the maximum number of code points that should be searched in {host-string}.
If less than 1, the function always fails and returns 0. If greater
than the valid length within the range, it is adjusted to the longest
valid length in the range. If not specified, the longest valid
length in the range is used.
Pos finds the last (right-most) occurrence of {sub-string} in {host-string} (so the search starts at the left-most position moving right through {host-string) and returns the position of the first character of {sub-string} as it stands in {host-string}.
This sample shows how to search a string for a substring using different search lengths and starting positions.
Assuming
String sTest
Integer iPos
Move "12341234" to sTest
The following code returns position 7, the right-most occurrence of '3'.
Move (RightPos("3", sTest)) to iPos
The following code returns position 3, the right-most occurrence of '3' between positions 1 and 6.
This means that the portion of the host string in blue is searched: "12341234".
Move (RightPos("3", sTest, 1, 6)) to iPos
The following code returns position 0, since '3' does not occur in the substring of sTest between positions 4 (starting position) and 5 (starting position + length 2).
This means that the portion of the host string in blue is searched: "12341234".
Move (RightPos("3", sTest, 4, 2)) to iPos
The following code returns position 7, the right-most occurrence of '3' following position 4.
This means that the portion of the host string in blue is searched: "12341234".
Move (RightPos("3", sTest, 4)) to iPos
If {sub-string} or {host-string} are of type other than string, its value will be converted to a string for output.