Nested number signs

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

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

In this example, number 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 number 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 number 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 place number 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 place number signs around function arguments.