Archive for February, 2010

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.