I have a list of strings and I need to remove the duplicates. I have tried a number of things, such as:
Using listRemoveDuplicates(list,",",true);
Using Ben Nadel's approach.
Using the ListDeleteDuplicates udf
Unfortunately, none of them worked. I'm really not sure what is going on. So any help would be appreciated.
I am currently using a free Developer's version of ColdFusion 10 in case that affects things.
Sample List:
lacunar_DM, Homocysteine, HTN, Tobacco, undetermined ,lacunar_DM,Homocysteine,Tobacco
This was created by appending a static list with a dynamic one pulled from a database:
<cfsavecontent variable= "lacunar_list">
lacunar_DM,
Homocysteine,
HTN,
Tobacco,
undetermined
</cfsavecontent>
<cfset combination = ListAppend(lacunar_list, lacunar)>
<cfoutput>
List before removing dups: #combination#<br/>
List after removing dups: #listremoveduplicates(combination, ",", true)#<br/>
</cfoutput>
Here are the results:
List before removing dups:
lacunar_DM, Homocysteine, HTN, Tobacco, undetermined ,lacunar_DM,Homocysteine,Tobacco
List after removing dups:
lacunar_DM, Homocysteine, HTN, Tobacco, undetermined ,lacunar_DM,Homocysteine,Tobacco
I think your problem is that your list contains extra white space. " Homocysteine" and "Homocysteine" are not the same values. Likewise, " Tobacco" and "Tobacco" are not the same values.
lacunar_DM, Homocysteine, HTN, Tobacco, undetermined ,lacunar_DM,Homocysteine,Tobacco
-----------^-------------^----^--------^------------^------------X------------X
As mentioned already, your list items contain extra white space. Looking at your list, all the items are using _
as spaces, so the simplest solution is to remove the spaces first, then remove the duplicates.
listRemoveDuplicates( Replace( YourList, " ", "", "ALL" ) )
If you do have some valid spaces, then I would suggest using a Trim()
around the fields when you compile the list manually.
YourList = ListAppend( YourList, Trim( ListItem ) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With