CFLib.org – Common Function Library Project

ListRemoveNulls(list[, delim])

Last updated May 26, 2003

author

Craig Fisher

Version: 1 | Requires: CF5 | Library: StrLib

Description:
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.

Example:

<cfset list1="1,2,,3,4">
<cfset list2=",1,2,,,,,3,4,,">
<cfset list3=",,,1,,,,2,,,3,,,,4,">
<cfoutput>
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>

</cfoutput>

Parameters:

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 (craig@altainteractive.com) 
 * @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

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson