ColdFusion ListToArray - includeEmptyField

Most ColdFusion developers have probably realized at some point that ListToArray ignores empty values between delimiters altogether.  What I mean is that "a,,,b,c,d" would return an array with only 4 items in it, rather than 6 items with two of them being empty.  This has been frustrating to say the least.  ColdFusion 8 to the rescue, ListToArray now has a third arguments "includeEmptyField" that defaults to false, but if true will not ignore empty values. See the following code for an example:

ColdFusion:
  1. <cfset letters="a,,,b,c,d" />
  2. <cfdump var="#listToArray(letters,',',true)#" label="listToArray(letters,',',true)" />
  3. <cfdump var="#listToArray(letters,',',false)#" label="listToArray(letters,',',false)" />

The above code results in the following output. Nothing unexpected here, but a welcome addition nonetheless.

2 Comments

  1. Emergence Says:

    I really have to read the docs better, I missed that extra attribute that was passed in.

    very cool

  2. scott Says:

    I agree it is cool. However, I also maintain this is more of a fix than an enhancement since to me it seemed crazy that there was no way to account for blank values before outside of replacing empty values with a arbitrary value.

Leave a Reply

You must be logged in to post a comment.