User Guide

Table Of Contents
82 Chapter 4: Using Expressions and Number Signs
Note: You do not need to use number signs when you use the cfset tag to assign one variable’s value
to another value. For example, the following tag assigns the value of the
oldVar variable to the new
variable,
newVar: <cfset newVar = oldVar>.
Using number signs in tag bodies
You can put variables or functions freely inside the bodies of the following tags by enclosing each
variable or expression with number signs:
cfoutput
cfquery
cfmail
For example:
<cfoutput>
Value is #Form.MyTextField#
</cfoutput>
<cfoutput>
The name is #FirstName# #LastName#.
</cfoutput>
<cfoutput>
The value of Cos(0) is #Cos(0)#
</cfoutput>
If you omit the number signs, the text, rather than the value, appears in the output generated by
the
cfoutput statement.
Two expressions inside number signs can be adjacent to one another, as in the following example:
<cfoutput>
"Mo" and "nk" is #Left("Moon", 2)##Mid("Monkey", 3, 2)#
</cfoutput>
This code displays the following text:
"Mo" and "nk" is Monk
ColdFusion does not interpret the double number sign as an escaped # character.
Using number signs in strings
You can put variables or functions freely inside strings by enclosing each variable or expression
with number signs; for example:
<cfset TheString = "Value is #Form.MyTextField#">
<cfset TheString = "The name is #FirstName# #LastName#.">
<cfset TheString = "Cos(0) is #Cos(0)#">
ColdFusion automatically replaces the 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 & "!">