See Also: String Functions, Ltrim, Mid, Right
Left returns the left-most code points of a string up to a specified length.
(Left( {string-value}, {length} ))
Where:
{string-value} is the string that characters will be extracted from
{length} is the number of code points from the left of {value} that are returned
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
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
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
If the {length} parameter = 0, the Left 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 type other than string, its value will be converted to a string for output.