July 20, 2008
For ColdFusion hosting try HostMySite.com. |
Home /
Groups /
ColdFusion Talk (CF-Talk)
delete duplicates
i have some duplicates in a list i need to deletemorchella 05/21/08 03:10 P I am sure there are few udf on cflib.org that can be used. Have you lookedQasim Rasheed 05/21/08 03:16 P http://www.cflib.org/udf.cfm?id=532Gerald Guido 05/21/08 03:45 P all that seems to do is to remove the commas?morchella 05/21/08 03:58 P You have to remove the dupes before you loop over the listGerald Guido 05/21/08 05:13 P An easy way to delete duplicates form a list is to loop the list into aBobby Hartsfield 05/21/08 05:16 P thanks guys.morchella 05/21/08 06:00 P http://63.144.103.199/products/partNumsTab3.cfm?n1ID=5&n2ID=43&n3ID=133morchella 05/22/08 10:04 A i have some duplicates in a list i need to delete but am not getting it once again. <cfloop From = "1" To = "#ListLen(getAce.specs_partnum)#" index = "Counter"> <cfoutput group="specs_partnum"> <cfset acccL = #ListGetAt(getAce.specs_partnum,Counter)#> <cfset acccL = ListSort("#acccL#","text", "ASC")> #acccL# </cfoutput></cfloop> <br /><br /> </cfoutput> spits out: Cable Management 9969593 9969593 9969599 9969599 9969594 9969594 9969600 9969600 9969599 9969599 9969601 9969601 9969600 9969600 9969928 9969928 9969601 9969601 9969927 9969927 9969928 9969928 9969597 9969597 9969927 9969927 9969736 9969736 9969597 9969597 9969595 9969595 9969736 9969736 9969598 9969598 9970253 9970254 9970255 9970256 9970263 9970264 9970265 9970266 9970271 9970271 9970271 9970271 thanks guys. I am sure there are few udf on cflib.org that can be used. Have you looked there? HTH On Wed, May 21, 2008 at 3:08 PM, morchella <morchella.deliciosa@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- http://www.cflib.org/udf.cfm?id=532 /** * Case-sensitive function for removing duplicate entries in a list. * @param list The list to be modified. * @return Returns a list. */ function ListDeleteDuplicates(list) { var i = 1; var delimiter = ','; var returnValue = ''; if(ArrayLen(arguments) GTE 2) delimiter = arguments[2]; list = ListToArray(list, delimiter); for(i = 1; i LTE ArrayLen(list); i = i + 1) if(NOT ListFind(returnValue, list[i], delimiter)) returnValue = ListAppend(returnValue, list[i], delimiter); return returnValue; } /** * Case-INsensitive function for removing duplicate entries in a list. * @param list List to be modified. * @return Returns a list. */ function ListDeleteDuplicatesNoCase(list) { var i = 1; var delimiter = ','; var returnValue = ''; if(ArrayLen(arguments) GTE 2) delimiter = arguments[2]; list = ListToArray(list, delimiter); for(i = 1; i LTE ArrayLen(list); i = i + 1) if(NOT ListFindNoCase(returnValue, list[i], delimiter)) returnValue = ListAppend(returnValue, list[i], delimiter); return returnValue; } On Wed, May 21, 2008 at 3:08 PM, morchella <morchella.deliciosa@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- all that seems to do is to remove the commas? <cfoutput query="getAce" group="title"> #title# x<br /> <cfloop From = "1" To = "#ListLen(getAce.specs_partnum)#" index = "Counter"> <cfoutput group="specs_partnum"> <cfset acccL = #ListGetAt(getAce.specs_partnum,Counter)#> <cfset acccL = '#acccL#,'> #ListDeleteDuplicates(acccL)# </cfoutput></cfloop> <br /><br /> </cfoutput> Cable Management x 9969593, 9969593, 9969599, 9969599, 9969594, 9969594, 9969600, 9969600, 9969599, 9969599, 9969601, 9969601, 9969600, 9969600, 9969928, 9969928, 9969601, 9969601, 9969927, 9969927, 9969928, 9969928, 9969597, 9969597, 9969927, 9969927, 9969736, 9969736, 9969597, 9969597, 9969595, 9969595, 9969736, 9969736, 9969598, 9969598, 9970253, 9970254, 9970255, 9970256, 9970263, 9970264, 9970265, 9970266, 9970271, 9970271, 9970271, 9970271, Cable Management x 9969593 9969593 9969599 9969599 9969594 9969594 9969600 9969600 9969599 9969599 9969601 9969601 9969600 9969600 9969928 9969928 9969601 9969601 9969927 9969927 9969928 9969928 9969597 9969597 9969927 9969927 9969736 9969736 9969597 9969597 9969595 9969595 9969736 9969736 9969598 9969598 9970253 9970254 9970255 9970256 9970263 9970264 9970265 9970266 9970271 9970271 9970271 9970271 You have to remove the dupes before you loop over the list On Wed, May 21, 2008 at 3:57 PM, morchella <morchella.deliciosa@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- An easy way to delete duplicates form a list is to loop the list into a structure using the list item as the key then use structKeyList() to get the cleaned list back out I don't know what your initial list looks like but here is an example with a space delimited list... <cfset theList = "9969593 9969593 9969599 9969599 9969594 9969594 9969600 9969600 9969599 9969599" /> <cfset uniqueListItems = structNew() /> <cfloop list="#theList#" delimiters=" " index="i"> <cfset uniqueListItems[i] = i /> </cfloop> <cfset cleanedList = structKeyList(uniqueListItems) /> .:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com all that seems to do is to remove the commas? <cfoutput query="getAce" group="title"> #title# x<br /> <cfloop From = "1" To = "#ListLen(getAce.specs_partnum)#" index = "Counter"> <cfoutput group="specs_partnum"> <cfset acccL = #ListGetAt(getAce.specs_partnum,Counter)#> <cfset acccL = '#acccL#,'> #ListDeleteDuplicates(acccL)# </cfoutput></cfloop> <br /><br /> </cfoutput> Cable Management x 9969593, 9969593, 9969599, 9969599, 9969594, 9969594, 9969600, 9969600, 9969599, 9969599, 9969601, 9969601, 9969600, 9969600, 9969928, 9969928, 9969601, 9969601, 9969927, 9969927, 9969928, 9969928, 9969597, 9969597, 9969927, 9969927, 9969736, 9969736, 9969597, 9969597, 9969595, 9969595, 9969736, 9969736, 9969598, 9969598, 9970253, 9970254, 9970255, 9970256, 9970263, 9970264, 9970265, 9970266, 9970271, 9970271, 9970271, 9970271, Cable Management x 9969593 9969593 9969599 9969599 9969594 9969594 9969600 9969600 9969599 9969599 9969601 9969601 9969600 9969600 9969928 9969928 9969601 9969601 9969927 9969927 9969928 9969928 9969597 9969597 9969927 9969927 9969736 9969736 9969597 9969597 9969595 9969595 9969736 9969736 9969598 9969598 9970253 9970254 9970255 9970256 9970263 9970264 9970265 9970266 9970271 9970271 9970271 9970271 thanks guys. will try that in the morning. such a beautiful day! http://63.144.103.199/products/partNumsTab3.cfm?n1ID=5&n2ID=43&n3ID=133 ok i am not getting the results i am expecting. i took the spaces out of the db.. but Cable Management still shows multiples. tried adding a ',' to the cfset so when the list loops it makes it one list. bbut its not removing duplicates.. any other ideas? Thanks! -m <cfquery name="getAce" datasource="xxx"> SELECT DISTINCT TOP 100 PERCENT title, specs_partnum, aId FROM dbo.VIEWtempAsc WHERE (aId IN (#aList#)) ORDER BY title </cfquery> <cfoutput query="getAce" group="title"> #title# - aId <cfoutput>#aId# </cfoutput><br /> <cfoutput><cfset theList = "#getAce.specs_partnum#," /></cfoutput> <cfset uniqueListItems = structNew() /> <cfloop list="#theList#" delimiters="," index="i"> <cfset uniqueListItems[i] = i /> </cfloop> <cfset cleanedList = structKeyList(uniqueListItems) /> <strong>theList</strong>: <cfoutput><strong>aId: #aId#</strong> #theList#</cfoutput><br /> <strong>cleanedList</strong>: <cfoutput>#cleanedList#</cfoutput><br /> <br /> <br /> </cfoutput><br /><br /> db looks like 28 Cable Management _ 600 Suited 7035 700/800 Alone 9969593,9969594,9969599,9969600,9969601,9969928,9969927,9969597,9969736,9970253,9970263,9970271 175 Cable Management _ 600 Suited 9005 700/800 Alone 9969593,9969594,9969599,9969600,9969601,9969928,9969927,9969597,9969736,9970254,9970264,9970271 176 Cable Management _ 700 Suited 7035 9969599,9969600,9969601,9969928,9969927,9969597,9969736,9969595,9969598,9970255,9970265,9970271 177 Cable Management _ 700 Suited 9005 9969599,9969600,9969601,9969928,9969927,9969597,9969736,9969595,9969598,9970256,9970266,9970271
|
Mailing Lists
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||