Yes, stick the 'items' into a dictionary as keys and check before
insertion - pseudo-code follows:
Dim itemList As Dictionary
Dim anItem As <youritemtype>
Dim myItemList() As <youritemtype>
Dim s As String
Dim myUniqueList() As <youritemtype>
Me.Fill myItemList // Some method for filling your list with items to
be checked.
For each anItem in myItemList
s = anItem.ToString() // Coerce anItem into a string
representation that we can use to check for duplicates
If itemList.DoesntHaveKey(s) Then
// Not a duplicate
itemList.Value(s) = ??? // whatever... we're just using the
keys, not their values
myUniqueList.Append anItem
End If
Next
When you're done, 'myUniqueList' will hold only the unique values
- you can then copy all the items back into 'myItemList', or just use
the new array as-is.
HTH!
On Sep 2, 2006, at 9:12 PM, Scott Goelzer wrote:
Hi All
I know there is a way to do this faster and better than what I
chunked together.
I need a to take a delimited list and remove all duplicate instances.
Anyway to do this faster with Regex? Still very new to me and
somewhat daunting.
Thanks
Scott
Function removeDuplicates(sourceString as string,delim as string)
As string
// We need to produce a string where none of the items are
duplicated.
dim n,i As integer
dim finalString As String
dim sourceArray(-1) As string
dim currentItem As string
sourceArray = Split(sourceString,delim)
for n = 0 to Ubound(sourceArray)
currentItem = sourceArray(n)
if currentItem <> "" then
finalString = finalString + currentitem + delim
sourceArray(n) = ""
for i = n to Ubound(sourceArray)
if sourceArray(i) = currentItem then
sourceArray(i) = ""
end if
next
end if
next
if right(finalString,len(delim)) = delim then
finalString = Left(finalString, len(finalString)-len(delim))
end if
return finalString
End Function
*******************************************
Scott Goelzer
Physics Teacher
Coe-Brown Northwood Academy
Northwood NH 03261
[EMAIL PROTECTED]
*******************************************
_______________________________________________
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>
_______________________________________________
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>