Critter’s Code

This is a picture of a bridge and a city. I like bridges and cities. They make me smile.

Dec-16-2009

Case sensitive keys in ColdFusion structures

I know this is old news, but this one bit me last night.

I needed to loop over a structure and return the keys and values in a case-sensitive xml format. Creating my structure like this:

1
2
3
4
5
<cfscript>
qHolder = structNew();
qHolder.userName = "Critter";
qHolder.firstName = "Critter";
</cfscript>

was returning the keys in all caps. (USERNAME, FIRSTNAME)

I had forgotten that if you need to preserve the case of the keys you need to create them like this:

1
2
3
4
5
<cfscript>
qHolder = structNew();
qHolder["userName"] = "Critter";
qHolder["firstName"] = "Critter";
</cfscript>

That will result in (userName, firstName). You can reference them with dot notation and the case will be preserved, so long as they are created using the [""] format.

As you were.

VN:F [1.7.5_995]
Rating: 0.0/10 (0 votes cast)
VN:F [1.7.5_995]
Rating: 0 (from 0 votes)
Posted under ColdFusion, Samples
blog comments powered by Disqus