During my presentation earlier this week, I brought up a few 'Gotchas' that ColdFusion developers may not be aware of. Today I'm going to review some of these for those who couldn't make the presentation.
The first item that came up was during my discussion of ColdFusion lists. The one thing I really see trip people up (and it tripped me up when I was building my first ColdFusion application - back in the dinosaur days) is the fact that list delimiters are only single characters - even if you pass multiple delimiters. So what do I mean? Consider this list:
<cfset monkeys = "King Kong__+__George, Bush__+__Clinton, Hillary__+__Super_Monkey">
Looking at this string you might think you could simply tell ColdFusion to use + as a delimiter. Consider this loop:
<cfloop index="item" list="#monkeys#" delimiters="__+__">
Many developers think that ColdFusion will do this: "Ok, take my string, and consider the literal string + as a delimiter." Instead, ColdFusion does this: "Ok, I'll use _ and + as delimiters."
What this means is that our loop will display:
The _ inside of Super_Monkey was considered a delimiter and therefore was split up by ColdFusion. In case you do want to split up a string by a set of characters, consider the split() UDF at CFLib.