On Sep 3, 2006, at 1:20 PM, Joe Huber wrote:
At 1:09 PM -0400 9/3/06, Charles Yeomans wrote:
Function removeDuplicates(sourceString as string,delim as string)
As string
dim sourceList() as String = Split(sourceString, delim)
dim d as new Dictionary
for i as Integer = 0 to UBound(sourceList)
d.Value(sourceList(i)) = true
next
dim lastKeyIndex as Integer = d.Count - 1
dim outputList(lastKeyIndex) as String
for i as Integer = 0 to lastKeyIndex
outputList(i) = d.Key(i)
next
return Join(outputList, delim)
End Function
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
Indeed it could. It might be interesting to compare performance. I
recall that iteration using For Each was slower at one time, but
perhaps that's changed.
I should also point out that this approach does use more memory than
Robert's in-place code.
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>