Switch Statements Not Case Sensitive

Posted July 31, 2006 at 8:01 AM by Ben Nadel

Tags: ColdFusion

I know that ColdFusion is case insensitive by nature. It had never occurred to me though that conditional statements were also case insensitive. I am such a huge user of ListFind() and Compare(), both of which are case SENSITIVE, that I just started to assume that all conditionals were case sensitive. That's the reason why my custom tags end up looking like:

  • <cfswitch expression="#UCase( THISTAG.ExecutionMode )#">
  • <cfcase value="START">
  • <!--- ... --->
  • </cfcase>
  • <cfcase value="END">
  • <!--- ... --->
  • </cfcase>
  • </cfswitch>

I upper case the ExecutionMode variable because I am never sure what value it is going to be. Apparently though, as I just found out, that is entirely unnecessary. Switch statements, as well as all other simple conditional statements, are NOT case sensitive. To experiment a bit, I tried doing this:

  • <!--- Set a value with mixed case. --->
  • <cfset strValue = "Cool">
  •  
  • <!--- Check values without case sensitivity. --->
  • <cfswitch expression="#strValue#">
  •  
  • <!--- Check with same case. --->
  • <cfcase value="Cool">
  • It is Cool.
  • </cfcase>
  •  
  • <!--- Check with lower case. --->
  • <cfcase value="cool">
  • It is cool.
  • </cfcase>
  •  
  • </cfswitch>

Both cases above are the same word, but with different letter casing. Turns out, the above example throws an error:

Context validation error for tag CFCASE.
The CFSWITCH has a duplicate CFCASE for value "COOL".

ColdFusion is seeing the two "Cool" cases as having the same value. Then, just to double-check that I am not going completely crazy, I tested the case-insensitive check without duplicate values:

  • <!--- Check values without case sensitivity. --->
  • <cfswitch expression="#strValue#">
  •  
  • <!--- Check with a different case. --->
  • <cfcase value="COOL">
  • This is COOL
  • </cfcase>
  •  
  • <!--- Check with different value. --->
  • <cfcase value="LAME">
  • This is LAME
  • </cfcase>
  •  
  • </cfswitch>

This one does indeed access the first case statement value of COOL even though the original value was mixed-case.

I am not 100% sure how I feel about this. On one hand, I like that fact that I don't have to worry about cases in conditional statements. On the other hand though, I like the fact that ListFind() and Compare() are case sensitive and that I can leverage that in certain ways. I guess overall, it is going to create less bugs. And, now that I know it, I don't have to waste processing power changing the letter-casing of my switch statements.



Reader Comments

There are no comments posted for this web log entry.

Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 16, 2012 at 8:18 PM
Best Of ColdFusion 10 Contest Entry - HTML Email Utility
Just found this, looks good! I'm trying to run it on local, it's the 64bit version and I'm experiencing horrible lag. On average the generate.cfm processes the content change in 60-90 seconds. I've ... read »
May 16, 2012 at 6:40 PM
Maintaining Sessions Across Multiple ColdFusion CFHttp Requests
I am trying to integrate this CFHTTPsession into an application that will log into zeekrewards.com to post ads and I am not having any luck. The code works perfectly for logging into other websites, ... read »
May 16, 2012 at 2:44 PM
Creating A Sometimes-Fixed-Position Element With jQuery
Thank you, very useful technique! Worked like a charm. ... read »
May 16, 2012 at 1:58 PM
Movies As A Religious Experience
Acting can, in a way, ruin the movie-goer's experience. I used to be able to get so caught up in movies and their plots, and totally engaged. But lately, I haven't been able to as much with a lot o ... read »
May 16, 2012 at 1:52 PM
The Science Of Optimal Post-Exercise Nutrition
children of this age eat very less vegetables so u can opt for salads they will like it also carrot ,cucumber,onion and as far as pulses are concerned u can boil them ,give him along with mashed rice ... read »
May 16, 2012 at 1:34 PM
Strange ColdFusion JRUN Stack Overflow Error
Hey, Recently I updated my jrun4 using the latest updater 7 and now i am having memory issues :(:(:( any help is appreciated ... read »
May 16, 2012 at 9:56 AM
ColdFusion 10 Beta, Apache Tomcat, And Symbolic Links On Mac OSX
Hi, Now that ColdFusion 10 is out I have stumbled over this as well and I cannot figure out the proper solution. We're running virtual hosts via Apache2; the ColdFusion-applications store their fil ... read »
May 15, 2012 at 6:03 PM
Movies As A Religious Experience
@Ben, I don't know whether you'd consider this a religious observation, but it seems to me, in a sense, movies multiply how many lives we get to have. Each movie is like a little extra life we get ... read »