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.
Posted under ColdFusion, Samples