User Guide Cancel

ListRemoveDuplicates

 

Description

Removes duplicate values (if they exist) in a list.

Returns

List sans duplicate values

History

ColdFusion 10: Added this function

Syntax

ListRemoveDuplicates(list[, delimiter] [, ignoreCase])
ListRemoveDuplicates(list[, delimiter] [, ignoreCase])
ListRemoveDuplicates(list[, delimiter] [, ignoreCase])

Properties

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.

Example 1

<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,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,five,three"
    newList = listRemoveDuplicates(myList); 
    //default delimeter is ","
    //newList contains "one,two,three,four,five"
    writeOutput(newList)
</cfscript>

Output

one,two,three,four,five

Example 2

<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 = "one,two,three,four,five,ONE,TWO,THREE" newList = listRemoveDuplicates(myList, ",", true); //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>

Output

one,two,three,four,five

Example 3

<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>
<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>
<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

Get help faster and easier

New user?