Contents > Developing ColdFusion MX Applications > Using Expressions and Pound Signs > Using pound signs > Nested pound signs PreviousNext

Nested pound signs

In a few cases, you can nest pound signs in an expression. The following example uses nested pound signs:

<cfset Sentence = "The length of the full name is
#Len("#FirstName# #LastName#")#">

In this example, pound signs are nested so that the values of the variables FirstName and LastName are inserted in the string whose length the Len function calculates.

Nested pound signs imply a complex expression that can typically be written more clearly and efficiently without the nesting. For example, you can rewrite the preceding code example without the nested pound signs, as follows:

<cfset Sentence2 = "The length of the full name is #Len(FirstName & " "
& LastName)#">

The following achieves the same results and can further improve readability:

<cfset FullName = "#FirstName# #LastName#">
<cfset Sentence = "The length of the full name 
   is #Len(FullName)#">

A common mistake is to put pound signs around the arguments of functions, as in:

<cfset ResultText = "#Len(#TheText#)#">
<cfset ResultText = "#Min(#ThisVariable#, 5 + #ThatVariable#)#">
<cfset ResultText = "#Len(#Left("Some text", 4)#)#">

These statements result in errors. As a general rule, never put pound signs around function arguments.


Contents > Developing ColdFusion MX Applications > Using Expressions and Pound Signs > Using pound signs > Nested pound signs PreviousNext

ColdFusion 9 | 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.

 

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

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