@Left (JavaScript)
Returns the leftmost characters of a string for the number of characters specified, or up to and excluding a substring.
Defined in
@Functions (JavaScript)Syntax
@Left(value:string, n:int) :
string@Left(value:string, subString:string) :
string
| Parameter | Description |
|---|---|
value |
The string to check. |
n |
Number of characters. The function returns the leftmost number of characters specified. A real number is truncated to an integer. |
subString |
A substring. The function returns the leftmost characters up to and excluding the substring. |
| Return value | Description |
|---|---|
string |
The leftmost characters. |
Usage
This function returns:- The entire string if
nexceeds the length of the string. - The entire string if
nis negative. - An empty string if
nis 0. - An empty string if
subStringis not found.
Examples
(1) This example gets the leftmost 5 characters, the rightmost 6 characters, and the characters less the first 6 and the last 7.function p(stuff) {
print("<<<" + stuff + ">>>");
}
var lineitem = "Q5212 peaches and cream 001.99";
var code = @Left(lineitem, 5);
var price = @Right(lineitem, 6);
var description = @LeftBack(@RightBack(lineitem, 6), 7);
p("Code = " + code); // Q5212
p("Price = " + price); // 001.99
p("Description = " + description); // peaches and cream(2) This example gets the leftmost characters up to the first space, the rightmost characters back to the last space, and the characters between the first and last spaces.
function p(stuff) {
print("<<<" + stuff + ">>>");
}
var lineitem = "Q5212 peaches and cream 001.99";
var code = @Left(lineitem, " ");
var price = @RightBack(lineitem, " ");
var description = @LeftBack(@Right(lineitem, " "), " ");
p("Code = " + code); // Q5212
p("Price = " + price); // 001.99
p("Description = " + description); // peaches and cream