Function Left() Foundation

Extracts part of a character string starting with the first character.

Syntax
Left( <cString>, <nCount> ) --> cSubString
Parameters
<cString>
<cString> is a character string from which a character substring is extracted starting with the leftmost character. The length of <cString> is not limited in Xbase++.
<nCount>
<nCount> is the number of characters which are extracted from <cString>.
Return

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.

Description

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.

Examples
Left()
// 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 
Extract path from complete file name

// 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 
Feedback

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.