> -----Original Message-----
> From: CFDEV [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, April 19, 2005 7:27 PM
> To: CF-Talk
> Subject: take duplicate out of a list
>
> Hi, is there an easy way to take duplicate out of a list or do I have to
> loop trough the list and create a new list with all elements and check if
> they are already in the new list before inserting them?
If the order of the list doesn't matter you can skip some of that with
regular expressions - but the list must be sorted.
Essentially you do a regex search for two of the list items in a row and
replace them with a single instance. You just have to keep looping until
you find no matches (because this will only eliminate pairs at a time).
The number of loops required is directly related to how many sets of dupes
more than two there are - for lists which are mostly unique already you
rarely need more than one loop.
Here's some sample code. "CurPlan" is a list of matched database ids (for
example something like "10:32,30:35,1:3543,34:645")
<cfset CurPlan = ListSort(CurPlan, "Numeric") & ",">
<cfset DupeMatch = 1>
<cfloop condition="#DupeMatch#">
<cfset CurPlan = ReReplace(CurPlan, "([0-9]+,)\1", "\1", "ALL")>
<cfset DupeMatch = ReFind("([0-9]+,)\1", CurPlan, 1, "False")>
</cfloop>
Of course, as I said, you have to sort the list for this work - if the
original order matters then this just isn't very useful.
Jim Davis
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:203607
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54