On 1/31/09 3:45 PM, "Charles Yeomans" <charles@declareSub.com> wrote:
> Someone else suggested using a Dictionary object. I suggest using it
> as follows.
>
> Function RemoveDuplicates(theList() as Integer) as Integer()
> dim d as new Dictionary
> dim newList() as Integer
> for i as Integer = 0 to UBound(theList)
> if not d.HasKey(theList(i)) then
> newList.Append theList(i)
> d.Value(theList(i) = nil
> end if
> next
> return newList
> End Function
It probably would be faster to predimension the array, especially for large
arrays. (And, this is supposed to be for strings.)
Function RemoveDuplicates(theList() as String) as String()
dim d as new Dictionary
dim lastIndex as Integer = theList.Ubound
dim newList( -1 ) as string
redim newList( lastIndex )
dim newIndex as Integer = 0
for each thisItem as String in theList
if d.HasKey( thisItem ) then
lastIndex = lastIndex - 1
else
newList( newIndex ) = thisItem
newIndex = newIndex + 1
d.Value( thisItem ) = nil
end if
next
redim newList( lastIndex )
return newList
End Function
This has been tested.
__________________________________________________________________________
Kem Tekinay (212) 201-1465
MacTechnologies Consulting Fax (914) 242-7294
http://www.mactechnologies.com Pager (917) 491-5546
To join the MacTechnologies Consulting mailing list, send an e-mail to:
mactechnologies_consulting-subscribe@yahoogroups.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|