WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

List Manipulation

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Remove Duplicates from a List

Keyword: Remove Delete Duplicates Duplicate Delimited List Item

Example 1:
#DefineFunction udfItemListTrimDup (strItemList, strDelimiter)
strTrimList = ""
intCount = ItemCount (strItemList, strDelimiter)
For intElem = 1 To intCount
   strItem = ItemExtract (intElem, strItemList, strDelimiter)
   If strItem != "" Then If !ItemLocate (strItem, strTrimList, strDelimiter) Then strTrimList = ItemInsert (strItem, -1, strTrimList, strDelimiter)
Next
Return strTrimList
...........................................................................................................................................
; This UDF udfItemListTrimDup returns an itemlist with empty items removed and duplicates removed.
...........................................................................................................................................
#EndFunction


Example 2:

#DefineFunction RemoveDupList(list,delim)
   list = ItemSort(list,delim)
   lastitem="dfrt456tgsdr436yter57857456345tefg577878765gdfgsdf345346rthdrg4352efhtyiu67uy4t"
   itemcnt=0
   newlist = ""
   For x = 1 To ItemCount(list,delim)
      item = ItemExtract(x,list,delim)
      If item != lastitem
         lastitem=item
         If newlist=="" Then newlist=item
         Else newlist = StrCat(newlist,delim,item)
      EndIf
   Next
   Return(newlist)
#EndFunction

list = "a b c c d a b b"
usedelim =" "  ; using a space as a delimiter for this example
newlist = RemoveDupList(list,usedelim)
AskItemlist( "Results", newlist, usedelim, @UNSORTED, @SINGLE )

Article ID:   W16251
File Created: 2010:04:26:09:04:12
Last Updated: 2010:04:26:09:04:12