Spec-Zone.ru › ColdFusion

right

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

right(String, count) → returns string

  • CF
  • Lucee
  • BL 1.0.0+
  • See Also: left mid

    Argument Reference

    String string
    Required

    count numeric
    Required

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

    Compatibility

    ColdFusion:

    The count can be a negative integer as of CF2018+

    Examples
    Sample code invoking the right function

    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 ) );

    Expected 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. CF 2018+

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

    Expected 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

    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

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API