left

Returns the leftmost count characters in a string.

left(String, count) → returns String

Member Function Syntax

string.left(count)

left Argument Reference

String String
Required

count Numeric
Required

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

Fork me on GitHub