Removes duplicate values (if they exist) in a list.
List sans duplicate values
ColdFusion 10: Added this function
ListRemoveDuplicates(list[, delimiter] [, ignoreCase])
Parameter |
Description |
|---|---|
list |
Required. List of objects. |
delimiter |
Optional. Character(s) that separate list elements. The default value is comma. . |
ignoreCase |
Optional. If true, ignores the case of strings in the list. By default the value is set to false. |
<cfscript>
myList = "one,two,three,four,five,one,five,three"
newList = listRemoveDuplicates(myList);
//default delimeter is ","
//newList contains "one,two,three,four,five"
writeOutput(newList)
</cfscript>
<cfscript>
myList = "one,two,three,four,five,ONE,TWO,THREE"
newList = listRemoveDuplicates(myList, ",", true);
//newList contains "one,two,three,four,five"
writeOutput(newList)
</cfscript>
<cfscript>
myList="London,Auckland,Seattle,Geneva,Berlin,Berlin,Rome,London,Seattle";
myList1="London,Auckland,Seattle,Geneva,Berlin,Berlin,Rome,London,Seattle,seattle,auckLand";
myCleanList=ListRemoveDuplicates(myList);
myCleanList1=ListRemoveDuplicates(myList1,",",false);
WriteOutput(myCleanList & " | "); // Removes duplicate items in the list
WriteOutput(myCleanList1); // Removes duplicate items after ignoring case
</cfscript>
Output
London,Auckland,Seattle,Geneva,Berlin,Rome | London,Auckland,Seattle,Geneva,Berlin,Rome,seattle,auckLand
Sign in to your account