views:

72

answers:

2

I'm using Coldfusion. I want to concatenate two strings into the same struct key, but I keep getting an error of "can't convert x into a boolean."

For example:

<cfset myStruct.string1 = nodes[1].string1.XmlText>
<cfset mystruct.string2 = nodes[1].string2.XmlText>

Neither of the following works

<cfset myStruct.concatendatedSring = nodes[1].string1.XmlText AND nodes[1].string2.XmlText>
<cfset myStruct.concatendatedSring = myStruct.string1 AND myStruct.string2>

Why does neither method work?

+11  A: 

& is the string concat operator, AND and && are boolean operators.

<cfset myStruct.concatendatedSring = myStruct.string1 & myStruct.string2>
Henry
Yap, it's right.
ppshein
+4  A: 

In addition to Henry's answer, you can also concatenate two strings like this:

<cfset myStruct.concatendatedSring="#myStruct.string1##myStruct.string2#">
Gert G
I did an informal test on Cf9 in the last couple of weeks, and was surprised to find that this method is *significantly* slower for a single concatenation. It's almost as bad for two. I think it is because of how CF handles execution areas, but that's a guess.
Ben Doom