@RightBack (JavaScript)

Returns the rightmost characters of a string minus the number of characters specified, or back to and excluding the last occurrence of a substring.

Defined in

@Functions (JavaScript)

Syntax

@RightBack(value:string, n:int) : string

@RightBack(value:string, rightBack:string) : string

Parameter Description
value The string to check.
n Number of characters. The function returns the rightmost characters minus the number of characters specified. A real number is truncated to a fraction.
rightBack A substring. The function returns the rightmost characters back to and excluding the last occurrence of the substring.
Return value Description
string The rightmost characters.

Usage

This function returns:
  • An empty string if n exceeds the length of the string.
  • The entire string if n is negative.
  • The entire 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