Left Function
See Also: String Functions, Ltrim, Mid, Right
Purpose
The Left function returns the left-most code points of a string up to a specified length.
Return Type
Syntax
(Left({string-value}, {length}))
Where:
- {string-value}: The string from which characters will be extracted.
- {length}: The number of code points from the left of {string-value} that are returned.
What It Does
The Left function 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 identifying character groups (words) before and after any space in the text.
Function SplitStringIntoWords String sText returns String[]
String sWord
String[] Words
Integer iWordCount
Integer 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 is 0, the
Leftfunction 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.