View comments | RSS feed

Left

Description

Determines the number of characters from the beginning of the string parameter to the location specified by the count parameter.

Return value

Number; count of characters.

Category

String functions

Syntax

Left(string, count)

See also

Right, Mid, Len

Parameters

Parameter Description
string
A string or a variable that contains one.
count
A positive integer or a variable that contains one. Number of characters to return.

Example

<h3>Left Example</h3>

<cfif IsDefined("Form.MyText")>
<!--- if len is 0, then err --->
  <cfif Len(FORM.myText) is not 0>
    <cfif Len(FORM.myText) LTE FORM.RemoveChars>
    <p>Your string <cfoutput>#FORM.myText#</cfoutput>
    only has <cfoutput>#Len(FORM.myText)#</cfoutput>
    characters. You cannot output the <cfoutput>#FORM.removeChars#
     </cfoutput>
    leftmost characters of this string because it is not long enough.
    <cfelse>
    <p>Your original string: <cfoutput>#FORM.myText#</cfoutput>
    <p>Your changed string, showing only the
     <cfoutput>#FORM.removeChars#</cfoutput> leftmost characters:
    <cfoutput>#Left(Form.myText, FORM.removeChars)#
    </cfoutput>
    </cfif>
  <cfelse>
  <p>Please enter a string
  </cfif>
</cfif>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


spage-mm said on Sep 1, 2002 at 6:58 AM :
The long-winded description isn't right. The left() string function simply
"Gets a specified number of characters from a string, starting at the left."

Just like the right() string function.
jfinlayson said on Sep 23, 2002 at 4:31 PM :
The "Return value" section is also incorrect. The return value is a string, not a number.
No screen name said on Nov 23, 2004 at 3:24 PM :
What's up with this Form.Mytext example. Actual value would make more sense?
jrunrandy said on Nov 27, 2004 at 1:09 PM :
Form.Mytext is a hypothetical value coming in from a form. As a writer, it's hard to please everyone with these examples. We can hard-wire a string value, but it's not real-world usage; alternatively, we can show variables coming from a form, but it's sometimes obscure.
John2 said on Mar 10, 2005 at 7:25 AM :
it would make sense to have a function that returns the character in the string at position x like in SQL
string = foo

LEFT(string,1) is f

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt22.htm