Len

Description

Determines the length of a string or binary object.

Returns

Number; length of a string or a binary object.

Function syntax

Len(string or binary object)

See also

ToBinary, Left, Right, Mid

History

ColdFusion MX: Changed Unicode support: ColdFusion supports the Java UCS-2 representation of Unicode character values 0–65535. (ColdFusion 5 and earlier releases supported ASCII values 1–255. When calculating a length, some string-processing functions processed the ASCII 0 (NUL) character, but did not process subsequent characters of the string.)

Parameters

Parameter

Description

string

A string, the name of a string, or a binary object

Example

<h3>Len Example</h3> 
 
<cfif IsDefined("Form.MyText")> 
    <!--- If len returns 0 (zero), then show error message. ---> 
    <cfif Len(FORM.myText)> 
        <cfoutput><p>Your string, <strong>"#FORM.myText#"</strong>, 
        has <strong>#Len(FORM.myText)#</strong> characters.</cfoutput> 
    <cfelse> 
        <p style="color: red; font-weight: bold">Please enter a string of more 
        than 0 characters.</p> 
    </cfif> 
</cfif> 
 
<form action = "<cfoutput>#CGI.SCRIPT_NAME#</cfoutput>" method="POST"> 
<p>Type in some text to see the length of your string.</p> 
 
<input type = "Text" name = "MyText"><br /> 
<input type = "Submit" name="Submit" value = "Count characters"><br> 
</form>