listCompare(List1, List2 [, Delim1] [, Delim2] [, Delim3])
Last updated June 25, 2009
Version: 2 | Requires: ColdFusion MX | Library: StrLib
Description:
Compares one list against another to find the elements in the first list that don't exist in the second list. Performs the same funciton as the custom tag of the same name.
Return Values:
Returns a delimited list of values.
Example:
<CFSET PartialList = "1,3,5,7,9">
<CFSET FullList2 = "1,2,3,4,5,6,7,8,9,10">
<CFSET PartialList2 = "1,3,5,7,9">
<CFSET FullList3 = "a,b,c,d,e,f,g">
<CFSET PartialList3 = "a,c">
<CFOUTPUT>
#ListCompare(FullList, PartialList, ";", ",", "|")#<BR>
#ListCompare(FullList2, PartialList2)#<BR>
#ListCompare(FullList3, PartialList3)#<BR>
</CFOUTPUT>
Parameters:
| Name | Description | Required |
|---|---|---|
| List1 | Full list of delimited values. | Yes |
| List2 | Delimited list of values you want to compare to List1. | Yes |
| Delim1 | Delimiter used for List1. Default is the comma. | No |
| Delim2 | Delimiter used for List2. Default is the comma. | No |
| Delim3 | Delimiter to use for the list returned by the function. Default is the comma. | No |
Full UDF Source:
<!---
Compares one list against another to find the elements in the first list that don't exist in the second list.
v2 mod by Scott Coldwell
@param List1 Full list of delimited values. (Required)
@param List2 Delimited list of values you want to compare to List1. (Required)
@param Delim1 Delimiter used for List1. Default is the comma. (Optional)
@param Delim2 Delimiter used for List2. Default is the comma. (Optional)
@param Delim3 Delimiter to use for the list returned by the function. Default is the comma. (Optional)
@return Returns a delimited list of values.
@author Rob Brooks-Bilson (rbils@amkor.com)
@version 2, June 25, 2009
--->
<cffunction name="listCompare" output="false" returnType="string">
<cfargument name="list1" type="string" required="true" />
<cfargument name="list2" type="string" required="true" />
<cfargument name="delim1" type="string" required="false" default="," />
<cfargument name="delim2" type="string" required="false" default="," />
<cfargument name="delim3" type="string" required="false" default="," />
<cfset var list1Array = ListToArray(arguments.List1,Delim1) />
<cfset var list2Array = ListToArray(arguments.List2,Delim2) />
<!--- Remove the subset List2 from List1 to get the diff --->
<cfset list1Array.removeAll(list2Array) />
<!--- Return in list format --->
<cfreturn ArrayToList(list1Array, Delim3) />
</cffunction>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
4 day(s) ago
Will Belden added
longTime
9 day(s) ago
James Sleeman added
quickSort
19 day(s) ago
Ben Forta added
GetHostAddress
22 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)