View comments | RSS feed
Contents > Developing ColdFusion MX Applications > Using Expressions and Pound Signs > Using pound signs PreviousNext

Using pound signs

Pound signs (#) have a special meaning in CFML. When the ColdFusion server encounters pound signs in CFML text, such as the text in a cfoutput tag body, it checks to see if the text between the pound signs is either a variable or a function.

Is so, it replaces the text and surrounding pound signs with the variable value or the result of the function. Otherwise, ColdFusion generates an error.

For example, to output the current value of a variable named Form.MyFormVariable, you delimit (surround) the variable name with pound signs:

<cfoutput>Value is #Form.MyFormVariable#</cfoutput>

In this example, the variable Form.MyFormVariable is replaced with the value assigned to it.

Follow these guidelines when using pound signs:

The following sections provide more details on how to use pound signs in CFML. For a description of using pound signs to create variable names, see Using pound signs to construct a variable name in assignments


Contents > Developing ColdFusion MX Applications > Using Expressions and Pound Signs > Using pound signs PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


JeffHouser said on Jan 15, 2004 at 2:43 PM :
#1+1# will work in CFMX!

Why is it recommended here not to do that? Is it leftover from previous version documentation or is there some hidden reason?
halL said on Jan 16, 2004 at 8:19 AM :
he statement is only partially correct.

It is acceptable to use expressions in pound signs in cfoutput blocks. For example, the following code is valid:

<cfset dogs=3>
<cfset cats=9>
<cfoutput>There are #dogs + cats# pets on hand</cfoutput>

(Note that code in of this form mixes logic and presentation, which may not be desirable from the point of view of style and ease of understanding.)

However, in a cfset statement or function, you must not use pound signs around the expression. For example, the following line generates an error:

<cfset foo=#1+2#>

Instead, use

<cfset foo=1+2>
DracTK said on Jun 15, 2005 at 8:08 PM :
Regarding "Use pound signs only where necessary, because unneeded pound signs slow processing." is there some real data that supports this claim? I tried to prove above to my co-workers and failed - tests of code with extra ## and without didn't show any speed difference. Even with 10000 of cfsets there was no difference I could notice. On the other hand, cfif is faster than cfcase.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/exprea13.htm