On Sep 4, 2006, at 8:55 AM, Walter Purvis wrote:
-----Original Message-----
Behalf Of Scott Goelzer
Subject: Re: Remove duplicate code improvements
Such a clever use of dictionaries, but
I messed around with this code and found that Join function
will not play nice since d.keys returns a variant array, not
a string array.
I tried d.keys().stringtype, but RB refuses.
Not too familiar with dictionaries, is there any way to use
the d.keys functions without running another loop?
On Sep 3, 2006, at 1:20 PM, Joe Huber wrote:
Seems to me this could be simplified even further
Function removeDuplicates(sourceString as string,delim as
string) As
string
dim sourceList() as String = Split(sourceString, delim)
dim d as new Dictionary
for each item as string in sourceList
d.Value(item) = true
next
return Join(d.keys, delim)
End Function
Here is an alternative that should work.
Function removeDuplicates(sourceString as string,delim as string)
As string
dim sourceList() as String = Split(sourceString, delim)
dim d as new Dictionary
dim sourceListCount As integer = UBound(sourcelist)
for i as integer = sourceListCount downto 0
if not d.HasKey(sourceList(i)) then
d.Value(sourceList(i)) = true
else
sourcelist.Remove(i)
end
next
return Join(sourceList, delim)
End Function
It should, but I think it will be slower than my code because you're
removing elements from the array. The point of using a Dictionary is
to exploit the fact that the keys form a set (i.e. no duplicates).
If you need to guarantee the order of the elements, then you might
need to do a bit more work.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>