ListDiff(list1, list2[, delimiters])
Last updated June 26, 2002
Version: 1 | Requires: CF5 | Library: StrLib
Description:
Compares two lists and returns the elements that do not appear in both lists.
Return Values:
Returns a string.
Example:
<CFOUTPUT>
ListDiff("1,2,3","1,3,4,5"): #ListDiff("1,2,3","1,3,4,5")#
</CFOUTPUT>
Parameters:
Name | Description | Required |
---|---|---|
list1 | First list to compare | Yes |
list2 | Second list to compare | Yes |
delimiters | Delimiter for all lists. Defualt is comma. | No |
Full UDF Source:
/**
* Compares two lists and returns the elements that do not appear in both lists.
Returns a list that contains the elementsrest between list1 and list2
*
* @param list1 First list to compare (Required)
* @param list2 Second list to compare (Required)
* @param delimiters Delimiter for all lists. Defualt is comma. (Optional)
* @return Returns a string.
* @author Ivan Rodriguez (wantez015@hotmail.com)
* @version 1, June 26, 2002
*/
function ListDiff(list1,list2) {
var delimiters = ",";
var listReturn = "";
var position = 1;
// default list delimiter to a comma unless otherwise specified
if (arrayLen(arguments) gte 3){
delimiters = arguments[3];
}
//checking list1
for(position = 1; position LTE ListLen(list1,delimiters); position = position + 1) {
value = ListGetAt(list1, position , delimiters );
if (ListFindNoCase(list2, value , delimiters ) EQ 0)
listReturn = ListAppend(listReturn, value , delimiters );
}
//checking list2
for(position = 1; position LTE ListLen(list2,delimiters); position = position + 1) {
value = ListGetAt(list2, position , delimiters );
if (ListFindNoCase(list1, value , delimiters ) EQ 0)
listReturn = ListAppend(listReturn, value , delimiters );
}
return listReturn;
}
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