|
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
List Comparison
Could some one please advise me how to compare two lists of Ids (oldList, newList) and decide which Ids have been added or deleted (in the newList compared to oldList) but ignore any item that are unchanged? Many thanks, KamruKamru Miah 07/08/08 10:35 A This might do it: http://cflib.org/index.cfm?event=page.udfbyid&udfid=149Adrian Lynch 07/08/08 10:39 A Here you go... try a UDF...Che Vilnonis 07/08/08 10:43 A Kamru,Tom McNeer 07/08/08 10:47 A Thanks to all those to responded.Kamru Miah 07/09/08 12:06 P > Could some one please advise me how to compare two lists of IdsLarry Lyons 07/09/08 12:50 P Could some one please advise me how to compare two lists of Ids (oldList, newList) and decide which Ids have been added or deleted (in the newList compared to oldList) but ignore any item that are unchanged? Many thanks, Kamru This might do it: http://cflib.org/index.cfm?event=page.udfbyid&udfid=149 Adrian www.adrianlynch.co.uk Could some one please advise me how to compare two lists of Ids (oldList, newList) and decide which Ids have been added or deleted (in the newList compared to oldList) but ignore any item that are unchanged? Many thanks, Kamru Here you go... try a UDF... http://cflib.org/udf/ListCompare http://cflib.org/udf/ListInCommon Regards, Che Could some one please advise me how to compare two lists of Ids (oldList, newList) and decide which Ids have been added or deleted (in the newList compared to oldList) but ignore any item that are unchanged? Many thanks, Kamru Kamru, > Could some one please advise me how to compare two lists of Ids (oldList, > newList) and decide which Ids have been added or deleted (in the newList > compared to oldList) but ignore any item that are unchanged? Take a look at the ListDiff and ListDiffDup functions on cflib.org -- Thanks, Tom Tom McNeer MediumCool http://www.mediumcool.com 1735 Johnson Road NE Atlanta, GA 30306 404.589.0560 Thanks to all those to responded. The ListDiff and ListInCommon UFDs seems to have solved my problem:) Kamru > Could some one please advise me how to compare two lists of Ids > (oldList, newList) and decide which Ids have been added or deleted (in > the newList compared to oldList) but ignore any item that are > unchanged? Many thanks, Kamru > Could some one please advise me how to compare two lists of Ids > (oldList, newList) and decide which Ids have been added or deleted (in > the newList compared to oldList) but ignore any item that are > unchanged? Many thanks, Kamru You might try this approach, taken from Rupesh Kumar's blog (http://coldfused.blogspot.com/2007/01/extend-cf-native-objects-harnessing.html). BTRW he's one of the Adobe engineers in India. First convert both lists to arrays using the list to array function, then use the equals method that's a part of CFMX's java base, as in <!--- convert your lists to arrays ---> <cfset array1 = ListToArray("1,2,3,4,5,6,7,8") /> <cfset array2 = ListToArray("2,3,4,5") /> <cfset array3 = ListToArray("1,2,3,4,5,6,7,8") /> <!--- Are the arrays equal? ---> <cfoutput> array1 equals array2 : #array1.equals(array2)#<br /> array1 equals array3 : #array1.equals(array3)#<br /> </cfoutput> Then to find out what items are different between two list you can use the removeAll method, as in: <!--- Duplicate the first array we don't mess it up ---> <cfset dupArray1 = Duplicate(array1) /> <!--- Remove any common items between the two arrays (and lists)---> <cfset dupArray1.removeAll(array2)> <!--- convert the array back to a list and report ---> Items in array1 not in array2: <cfoutput>#arrayToList(dupArray1)# hth, larry
|
Mailing Lists
|
Latest Fusion Authority Articles
|
||||||