CFLib.org – Common Function Library Project

ListDeleteDuplicates(list)

Last updated July 2, 2008

Version: 1 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 5 time(s). Average Rating: 4.4

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:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson