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.

Run Example

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+

Run Example

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.

Run Example


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.

Run Example


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

Additional Examples

Run Example

// 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.

Last updated

Was this helpful?