Search

I'll be at


I support





Subscribe

Recent entries

Archives by subject

Archives by date

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
8
Aug

String Operators in ColdFusion 8: & and &=

ColdFusion already supports string concatenation using "&" operator.

ColdFusion 8 introduces a new string operator "&=" for compound concatenation.

<cfset sFirstName = "Indy">
<cfset sLastName = "Nagpal">
<cfset spacer = " ">

<cfoutput>
   variables.sFirstName = #sFirstName#<br/>
   variables.sLastName = #sLastName#<br/>
   variables.spacer = " "
</cfoutput>

<!--- & Concatenates strings --->
<cfset variables.sFullName = variables.sFirstName & spacer & variables.sLastName>

<p><strong>Concatanation using &</strong></p>
<p><cfoutput>#variables.sFullName#</cfoutput></p>

<!--- &= Compound concatenation. The variable on the right is used as both an element in the concatenation operation and the result variable. Thus, the expression a &= b is equivalent to a = a & b.
An expression can have only one compound assignment operator.
--->

<cfset variables.sFullName = variables.sFirstName>
<cfset variables.sFullName &= spacer>
<cfset variables.sFullName &= variables.sLastName>

<p><strong>Concatanation using &=</strong></p>
<cfoutput>#variables.sFullName#</cfoutput>

This code yields the following output. =======Start output======= variables.sFirstName = Indy
variables.sLastName = Nagpal
variables.spacer = " "

Concatanation using &

Indy Nagpal

Concatanation using &=

Indy Nagpal =======End output======= More information on string operators in ColdFusion 8 is at Adobe ColdFusion 8 Livedocs

Related entries

Comments