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
Compatibility
ColdFusion:
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 a negative count right() to return part of a string. CF 2018+
writeOutput( right( 'The quick brown fox jumped over the lazy dog', -32 ) ); Expected Result: the 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();
}
© 2012–present Foundeo, Inc. and the CFDocs contributors.
Licensed under the MIT License.
ColdFusion is a trademark of Adobe Systems Incorporated.
https://cfdocs.org/right