@Right (JavaScript)
Returns the rightmost characters of a string for the number of characters specified, or starting after a substring.
Defined in
@Functions (JavaScript)Syntax
@Right(value:string, n:int)
: string
@Right(value:string, subString:string)
: string
Parameter | Description |
---|---|
value |
The string to check. |
n |
Number of characters. The function returns the rightmost number of characters specified. A real number is truncated to an integer. |
substring |
A substring. The function returns the rightmost characters after the substring. |
Return value | Description |
---|---|
string |
The rightmost characters. |
Usage
This function returns:- The entire string if
n
exceeds the length of the string. - The entire string if
n
is negative. - An empty string if
n
is 0. - An empty string if
subString
is 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