Skip to content

Right

See Also: String Functions, Left, Mid, Pos, Rtrim

Purpose

The Right function returns the right-most code points of a string up to a specified length.

Return Type

String

Syntax

(Right({string-value}, {length}))

Where:

  • {string-value}: The string that characters will be extracted from.
  • {length}: An integer value indicating the number of code points that are extracted from the right of {string-value}.

What It Does

The Right function returns the trailing (right-most) code points of {string-value} up to and including the character in position {length} as counted backwards from the end of the string.

String sName
Move "John Smith" to sName
Move (Right(sName, 5)) To Customer.LastName

In this example, the last 5 characters of the value in the variable sName ("Smith") would be moved to the database field Customer.LastName.

Sample

This sample separates a string into words by separating character groups (words) before and after any space in the text.

Function SplitStringIntoWords String sText returns String[]
    String sWord
    String[] Words
    Integer iWordCount iSpacePos

    // Repeat as long as sText contains data
    While (sText <> "")
        // Find the first/next space
        Move (Pos(" ", sText)) To iSpacePos

        // If a space was found
        If (iSpacePos > 0) Begin
            // Take the left part
            Move (Left(sText, iSpacePos - 1)) To sWord

            // Move the remainder to the text variable
            Move (Right(sText, Length(sText) - iSpacePos)) To sText
        End
        // If no more spaces are found
        Else Begin
            // Make word equal to the text
            Move sText To sWord

            // Empty text to stop the loop
            Move "" To sText
        End

        Move sWord to Words[iWordCount]
        Increment iWordCount
    Loop

    Function_Return Words
End_Function

Procedure OnClick
    String sText
    String[] Words

    Move "Split this text into words" To sText
    Get SplitStringIntoWords sText to Words
End_Procedure

Notes

  • If the {length} parameter = 0, the Right function will return an empty string. If {length} is less than 0, the function will return the {string-value} parameter in its entirety. If {length} is greater than the number of characters in {string-value}, the function returns {string-value} in its entirety.

  • If the {string-value} parameter is of a type other than string, its value will be converted to a string for output.