ListDeleteDuplicates(list)
Last updated July 02, 2008
Version: 1 | Requires: CF5 | Library: StrLib
Description:
Simply pass it a list and optional delimiter. The function will look for case-sensitive matches, removing any it finds, and return a new list without duplicates.
Return Values:
Returns a list.
Example:
<cfset myList = "apples,oranges,apples,bananas,ORANGES">
<cfoutput>
List before removing dupes: #myList#<br>
List after removing dupes: #ListDeleteDuplicates(myList)#
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
list | The list to be modified. | Yes |
Full UDF Source:
/**
* Case-sensitive function for removing duplicate entries in a list.
* Based on dedupe by Raymond Camden
*
* @param list The list to be modified. (Required)
* @return Returns a list.
* @author Jeff Howden (cflib@jeffhowden.com)
* @version 1, July 2, 2008
*/
function ListDeleteDuplicates(list) {
var i = 1;
var delimiter = ',';
var returnValue = '';
if(ArrayLen(arguments) GTE 2)
delimiter = arguments[2];
list = ListToArray(list, delimiter);
for(i = 1; i LTE ArrayLen(list); i = i + 1)
if(NOT ListFind(returnValue, list[i], delimiter))
returnValue = ListAppend(returnValue, list[i], delimiter);
return returnValue;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016