View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > Len PreviousNext

Len

Determines the length of a string or binary object.

Number; length of a string or a binary object.

String functions

Len(string or binary object)

ToBinary, Left, Right, Mid

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.)

Parameter

Description

string

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

<h3>Len Example</h3>

<cfif IsDefined("Form.MyText")>
<!--- if len is 0, then err --->
   <cfif Len(FORM.myText) is not 0>
   <p>Your string, <cfoutput>"#FORM.myText#"</cfoutput>,
   has <cfoutput>#Len(FORM.myText)#</cfoutput> characters.
   <cfelse>
   <p>Please enter a string of more than 0 characters.
   </cfif>
</cfif>

<form action = "len.cfm">
<p>Type in some text to see the length of your string.

<br><input type = "Text" name = "MyText">
<br><input type = "Submit" name = "Remove characters">
</form>

Contents > CFML Reference > ColdFusion Functions > Len PreviousNext

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

Version 6.1

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

Comments


Sarge said on Mar 20, 2004 at 9:25 AM :
We are working to improve the examples in the ColdFusion reference pages. We propose to replace the current example on this page with the the following example. If you have any comments on this example, add them to this page.

This example shows how to use the len function to return length of a string.


<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>
Rita Atwood said on Feb 11, 2005 at 12:56 PM :
Yes, the new code works (the old code does not work with CF 6).

Thanks
mysorian said on Sep 8, 2005 at 5:53 AM :
You should device an example for the other argument, Binary Object!

 

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

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functib3.htm