Using number signs in strings

You can place 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 & "!">

If number signs are omitted inside the string, the text, rather than the value, appears in the string. For example, the following pairs of cfset statements produce the same result:

<cfset TheString = "Hello, FirstName!"> 
<cfset TheString = "Hello, " & "First" & "Name!">

As with the cfoutput statement, two expressions can be adjacent to each other in strings, as in the following example:

<cfset TheString = "Monk is #Left("Moon", 2)##Mid("Monkey", 3, 2)#">

The double-quotation marks around "Moon" and "Monkey" do not need to be escaped (as in ""Moon"" and ""Monkey""). This is because the text between the number signs is treated as an expression; it is evaluated before its value is inserted inside the string.