User Guide

582 CFML Language Reference
Complex expressions
Complex expressions involving one or more operators cannot be inserted inside
CFOUTPUT tags. The following example will produce an error.
<CFOUTPUT>1 + 1 is #1 + 1#</CFOUTPUT>
To insert the value of a complex expression in the output generated by a CFOUTPUT
statement, use CFSET to set a variable to the value of the expression and use that
variable inside the CFOUTPUT statement, as is shown below:
<CFSET Result=1 + 1>
<CFOUTPUT>1 + 1 is #Result#</CFOUTPUT>
Pound signs inside strings
Expressions containing a single variable or a single function can be used inside strings
as long as they are enclosed in pound signs.
<CFSET TheString="Value is #Form.MyTextField#">
<CFSET TheString="The name is #FirstName# #LastName#.">
<CFSET TheString="Cos(0) is #Cos(0)#">
ColdFusion automatically replaces the expression text with the value of the variable or
the value returned by the function. For example, the following pairs of CFSET
statements produce the same result:
<CFSET TheString="Hello, #FirstName#!">
<CFSET TheString="Hello, " & FirstName & "!">
If pound signs are not used around these expressions, the expression text as opposed
to the expression value will appear 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 in the case of the CFOUTPUT statement, in strings two expressions can be adjacent
to each other, as in
<CFSET TheString="Monk is #Left("Moon", 2)##Mid("Monkey", 3, 2)#">
Note that the double quotes around “Moon” and “Monkey” need not be escaped (or
doubled, as in ""Moon"" and ""Monkey""). This is because the text between the pound
signs is treated as an expression that is evaluated first before its value is inserted inside
the string.
Inserting complex expressions in strings
Complex expressions involving one or more operators cannot be inserted inside
strings. The following example produces an error:
<CFSET TheString="1 + 1 is #1 + 1#">