User Guide
Chapter 4: ColdFusion Expressions: Operators and Other Constructs 581
Pound Signs
Pound signs (#) have special meaning in ColdFusion. When a CFML application page
is processed, ColdFusion treats text delimited by pound signs differently from plain
text.
Two simple and very important points about pound signs in CFML are:
• Use pound signs to distinguish expressions from plain text.
• When expressions are evaluated, the resulting value is substituted for the
expression text.
For example, to output the current value of a variable named “Form.MyFormVariable,”
you must delimit the variable name with pound signs:
<CFOUTPUT>Value is #Form.MyFormVariable#</CFOUTPUT>
When ColdFusion processes an expression, it replaces the text of the expression and
the two pound signs around it with its resulting value. In the example above, the
expression #Form.MyFormVariable# is replaced with whatever value has been
assigned to it.
While the guidelines for using pound signs in CFML are simple, there is still some
possibility for confusion to arise. This is particularly true in cases where expressions
and plain text are mixed together. The following sections provide more details on how
pound signs should be used in CFML.
Pound signs inside CFOUTPUT tags
Expressions containing a single variable or a single function can be used freely inside
CFOUTPUT tags as long as they are enclosed in pound signs.
<CFOUTPUT>
Value is #Form.MyTextField#
</CFOUTPUT>
<CFOUTPUT>
The name is #FirstName# #LastName#.
</CFOUTPUT>
<CFOUTPUT>
Cos(0) is #Cos(0)#
</CFOUTPUT>
If pounds are not used around these expressions, the expression text rather than the
expression value will appear in the output generated by the CFOUTPUT statement.
Note that two expressions inside pound signs can be adjacent to one another, as in
<CFOUTPUT>
"Mo" and "nk" is #Left("Moon", 2)# #Mid("Monkey", 3, 2)#
</CFOUTPUT>