left
Returns the leftmost count characters in a string.
left(String, count) → returns string
Member Function Syntax
string.left(count)
Argument Reference
String string Required
count numeric Required
Compatibility
ColdFusion:
Examples Sample code invoking the left function
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
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
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 );
} 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!' );
} 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