|
|
Joined: Dec 1999
Posts: 30,867
Master Elite Member
|
Public Function String_PurgeDups(MyString As String, CaseSens As Boolean) As String
'Purpose
' Used to remove duplicate characters from a string.
'Parameters
' MyString (String) = The string we're working with.
' CaseSens (Boolean) = If True, characters are only considered duplicates if they match case.
' If False, characters are considered duplicates even if they don't match case.
'Return (String)
' Returns MyString with all duplicate characters removed.
' Returns a zero-length string if:
' MyString is zero-length.
'Dependencies
' String_CountChar()
'Version History
' 1.0 3/27/2006 3:20am Tested by Russ Tanner on VB 6 Win 2000
'---
'Initiate variables
Dim i As Long 'index into MyString
Dim R As String 'return buffer
'Traverse all characters in MyString
For i = 1 To Len(MyString)
'The current character has no duplicates, append it to the return string
If String_CountChar(R, Mid(MyString, i, 1), CaseSens) = 0 Then R = R & Mid(MyString, i, 1)
Next i
'Return the result
String_PurgeDups = R
End Function
|
|
|
|
|