RightPos

See Also: String Functions, Pos, Left, Length, Mid, Right

Purpose

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.

Return Type

Integer

Syntax

(RightPos( {sub-string}, {host-string} [, {StartingPosition}] [, {length} ] ))

Where:

What It Does

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}.

 Sample

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

Notes