Function Left() Foundation
Extracts part of a character string starting with the first character.
Left( <cString>, <nCount> ) --> cSubString
Left() returns the first <nCount> characters from <cString> as a character string. When <nCount> is less than or equals zero, a null string ("") is returned. When <nCount> is greater than the length of <cString>, <cString> is returned.
The character function Left() extracts part of a character string beginning with the first character. The result is the same as calling SubStr(<cString>, 1, <nCount>). The counterpart to the function Left() is the function Right() which extracts a part of a character string from the end (from the right).
The functions Left(), Right() and SubStr() extract parts of a character string and are often used with the functions At() and RAt() to determine the position of the substring within the character string.
// The example shows various results of the function Left()
PROCEDURE Main
? Left("Xbase++", 5) // result: Xbase
? Left( Time(), 5) // result: 15:36
? Left( CMonth(Date()), 3) // result: Dec
RETURN
// The example extracts the file path from a
// complete file name.
PROCEDURE Main
LOCAL cFileName := "C:\XBASE\APPS\DBF\CUSTOMER.DBF"
LOCAL cDirectory:= "" , n
DO WHILE ( n := At( "\", cFileName ) ) > 0
cDirectory += Left( cFileName, n )
cFileName := SubStr( cFileName, n+1)
ENDDO
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.