BackUp LevelNext

Pound Signs Inside String Expressions

Developers must be careful when using pound signs inside string expressions. Consider the following example as a guideline on when to use pound signs inside string expressions:

<CFSET A=2>
<CFSET Expression1="1 + #A#">
<CFSET Expression2="1 + A"> <BR>
<!--- This will produce a 3 --->

<CFOUTPUT>#Evaluate(Expression1)#</CFOUTPUT> <BR>

<!--- This will produce a 3 also --->

<CFOUTPUT>#Evaluate(Expression2)#</CFOUTPUT> <BR>

<!--- Now change the value of A --->

<CFSET A=5> <BR>

<!--- This will produce a 3 again, because Expression1
is equal to the string "1 + 2". The value of A,
which was 2 at the time Expression1 got its value
was directly inserted into the expression text. --->

<CFOUTPUT>#Evaluate(Expression1)#</CFOUTPUT> <BR>

<!--- This will produce a 6, because Expression2
is equal to "1 + A". The name, rather than the
value of the variable A was inserted into the
text of Expression2. --->

<CFOUTPUT>#Evaluate(Expression2)#</CFOUTPUT> <BR>

Note

To build dynamic expressions with variables inside them, do not use pound signs around the variable names when you build the expression text.


BackUp LevelNext

allaire

AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.