ColdFusion Tutorial

When to use # or not

There have been a endless debates about when to use a # around ColdFusion variables. Here?s my opinion about that:

Try to avoid the # and if the code doesn?t work properly without it, us the #.

Example:

<cfset doesn?t require # signs.

<cfset var1 = "Hey">
<cfset var2 = myvar>

Unless the variable is in a string:
<cfset var1 = "You have purchased #product# from our store.">
Try this instead:
<cfset var1 = "You have purchased " & product & " from our store.">

Notice: CFOUTPUT usually requires a #.
<cfoutput>#var1#</cfoutput>

ColdFusion Tutorial test

When to use # or not

No test is available or implemented for this ColdFusion Tutorial.

User Comments: 1

 How to find "&" in the string stored in a variable

Variable="This is my Question & I would appreciate any help?"
AnotherVariable = "#Variable#"

Question is how can I replace "&" in the above string with any otehr thing (say AND) while passing value of Variable to Another Variable.

Add your comments

Your Name*:
Your Email:
Site URL:
Site Name:
Comemt Title*:
Your Comment*:
Key Phrase*:
0bQ
Your IP Address: 38.103.63.60
 

ScandicWeb is own by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.