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

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

<cfscript> 
myList = "one,two,three,four,five,one,five,three" 
newList = listremoveduplicates(myList); 
//default delimeter is "," 
//newList contains "one,two,three,four,five" 
</cfscript>


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

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy