right

Gets a specified number of characters from a string,
beginning at the right.

right(String, count) → returns string

Argument Reference

String string
Required

count numeric
Required

A positive integer or a variable that contains one.
Number of characters to return.

Examples
Sample code invoking the right function

In this example we'll use right() to return part of a string.

writeOutput( right( 'The quick brown fox jumped over the lazy dog', 8 ) );

Expected Result: lazy dog

In this example we'll use right() in a function to help us to capitalize the last letter in a string.

public string function capitalizeLast( required string text ) {
	return  left( arguments.text, len( arguments.text ) - 1 ) & uCase( right( arguments.text, 1 ) );
}

In this example we'll use right() to test the last five characters of a request context variable.

if( listFindNoCase( 'super,great,coder,rulez', right( rc.answer, 5 ) ) ) {
	writeOutput( 'You are an awesome developer!' );
}

CF 11+ Lucee 4.5+ In this example we'll use right() as a member function inside a function to help us to capitalize the last letter in a string.

public string function capitalizeLast( required string text ) {
	return arguments.text.left( arguments.text.len() - 1 ) & arguments.text.right( 1 ).ucase();
}

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub