Click or drag to resize

Left Function

X#
Extract a substring beginning with the first character in a string.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.21
Syntax
 FUNCTION Left(
	cString AS STRING,
	dwCount AS DWORD
) AS STRING
Request Example View Source

Parameters

cString
Type: String
The string from which to extract characters.
dwCount
Type: DWord
The number of characters to extract.

Return Value

Type: String
The leftmost dwCount characters of cString.
If dwCount is negative or 0, Left() returns a NULL_STRING.
If dwCount is larger than the length of the string, Left() returns the entire string.
Remarks
Left() is the same as Substr(cString, 1, wCount). Left(), Right(), and Substr() are often used with both the At() and RAt() functions to locate the first and/or the last position of a substring before extracting it.
Examples
This example extracts the first three characters from the left of the target string:
X#
1? LEFT("ABCDEF", 3)                    // ABC
This example extracts a substring from the beginning of a string up to the first occurrence of a comma:
X#
1LOCAL cName := "James, William" AS STRING
2? LEFT(cName, AT(",", cName))        // James
See Also