– Common Function Library Project

ListRemoveNulls(list[, delim])

Last updated May 26, 2003


Craig Fisher

Version: 1 | Requires: CF5 | Library: StrLib

Rather than replacing null entries with a "countable" value (like NULL) ListRemoveNulls() simply removes then from the list entrely. This is a modified version of the ListFix UDF written by Patrick McElhaney which is a modified version of the ListFix UDFwritten by Raymond Camden.

Return Values:
Returns a string.


<cfset list1="1,2,,3,4">
<cfset list2=",1,2,,,,,3,4,,">
<cfset list3=",,,1,,,,2,,,3,,,,4,">
List one:#list1#<br>
List one without nulls: #ListRemoveNulls(list1)#<br>
List two:#list2#<br>
List two without nulls: #ListRemoveNulls(list2)#<br>
List three:#list3#<br>
List three without nulls: #ListRemoveNulls(list3)#<br>



Name Description Required
list List to parse. Yes
delim List delimiter. Defaults to a comma. No

Full UDF Source:

 * Removes null entries from lists.
 * @param list 	 List to parse. (Required)
 * @param delim 	 List delimiter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Craig Fisher ( 
 * @version 1, May 26, 2003 
function ListRemoveNulls(list) {
  var delim = ",";
  if(arrayLen(arguments) gt 1) delim = arguments[2];
  while (Find(delim & delim, list) GT 0){
      list = replace(list, delim & delim, delim, "ALL");
  if (left(list, 1) eq delim) list = right(list, Len(list) - 1);
  if (right(list, 1) eq delim) list = Left(list, Len(list) - 1);
  return list;
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson