Spec-Zone.ru › ColdFusion

left

Returns the leftmost count characters in a string.

left(String, count) → returns string

Member Function Syntax

string.left(count)

  • CF
  • Lucee
  • BL 1.0.0+
  • See Also: right 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 left function

    Using left() on a string

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

    writeOutput( left( 'The quick brown fox jumped over the lazy dog', 19 ) );

    Expected Result: The quick brown fox

    Using left() with a negative count on a string

    CF 2018+ In this example we'll use a negative count to return part of a string. CF 2018+

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

    Expected Result: The quick brown fox

    Using left() in a function

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

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

    Using left() to test values

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

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

    Using left() as a member function

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

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

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/left

    Spec-Zone.ru

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