ListRemoveNulls(list[, delim])
Last updated May 26, 2003
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;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016