Alternatively -- 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 nextdim 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
It all depends on the cost of the operations. Likely the cost of intializing and updating a dictionary will be more than the cost of the string search. OTOH, if the string is expected to be very long, using a dictionary is probably the way to go.
A really efficient version of the code would probably traverse the string, and instead of removing the duplicates, replace them with a sequence of commas (assuming that an empty string is not going to be one of the inputs; if so, another delimiter that won't be present) so as to avoid all the byte movement. But at a certain point, the dictionary is going to win out because of the efficiency of using the hash to deal with duplicates.
_______________________________________________ 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>
