Left

See Also: String Functions, Ltrim, Mid, Right

Purpose

Left returns the left-most code points of a string up to a specified length.

Return Type

String

Syntax

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

Where:

What It Does

Left returns the first (left-most) characters of {string-value} up to and including the character in Position {length}.

Move (Left(sName, 5)) To Customer.Firstname

Sample

This sample reverses the letters in a string.

Move "Joe Smith" To sName

Move (Pos (" ", sName)) To iPos

Move (Right (sName, Length (sName) - iPos) + ", " + Left (sName, iPos)) To sReversedName

 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