Mar 03

It's such a simple thing but I actually googled this because I couldn't think of it offhand.

CODE:
  1. <cfif len(str)>
  2.      <cfoutput>#str#</cfoutput>
  3. </cfif>

if str has zero characters, len(str) will return 0, mimicking behaviour of false. Cool!

2 Responses to “ColdFusion Checks String Length”

  1. Joshua Curtiss Says:

    You'll find this is a common shortcut in most langs, actually. Of course, some argue it is poor practice because it is less readable; others say it is better because it is less code.

    Here's another cool thing you can do:

    The alternative would be a clumsy if statement to do the assignment.

  2. Joshua Curtiss Says:

    I was wondering if I needed to escape the code.. Here's the code snippet:

    <cfset IsItBig = (MyNum GT 10000)>

Leave a Reply