User Guide

Table Of Contents
Using number signs 83
If number signs are omitted inside the string, the text, rather than the value, appears in the string.
For example, the following pairs of
cfset statements produce the same result:
<cfset TheString = "Hello, FirstName!">
<cfset TheString = "Hello, " & "First" & "Name!">
As with the cfoutput statement, two expressions can be adjacent to each other in strings, as in
the following example:
<cfset TheString = "Monk is #Left("Moon", 2)##Mid("Monkey", 3, 2)#">
The double-quotation marks around "Moon" and "Monkey" do not need to be escaped (as in
""Moon"" and ""Monkey""). This is because the text between the number signs is treated as an
expression; it is evaluated before its value is inserted inside the string.
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 put 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 put number signs around function
arguments.
Using number signs in expressions
Use number signs in expressions only when necessary, because unneeded number signs reduce
clarity and can increase processing time. The following example shows the preferred method for
referencing variables:
<cfset SomeVar = Var1 + Max(Var2, 10 * Var3) + Var4>