Right
Extract the rightmost count characters from a string
Method Signature
Right(string=[string], count=[integer])
Arguments
Argument
Type
Required
Description
Default
string
string
true
The string to extract from
count
integer
true
The number of characters to retrieve.
Examples
Using right() on a string
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 ) );
Result: lazy dog
Using right() with a negative count on a string
In this example we'll use a negative count right() to return part of a string. CF2018+
writeOutput( right( "The quick brown fox jumped over the lazy dog", -32 ) );
Result: the lazy dog
Using right() in a function
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 ) );
}
Using right() to test values
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!" );
}
Using right() as a member function
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();
}
Additional Examples
// simple Function
writeDump( right( "I love boxlang", 5 ) ); // boxlang
// Member function
str = "Save trees, save life on the earth.";
writeDump( str.right( 23 ) );
// save life on the earth.
Related
Last updated
Was this helpful?