Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb6-When there is no Delimiter in word -how to find Duplicate letters in String

Status
Not open for further replies.

LalithaPrabu

Programmer
Jul 23, 2020
1
0
0
US
When there is no Delimiter to find Duplicate letters in String in VB6 -tried the below one. Is there any easier method than this?
Function RemoveDuplicateLetter(ByVal MyString As String) As String
On Error GoTo vbErrorHandler
Dim MyArr As Variant, MyNewArr() As String, X As String
Dim bValue As Boolean
Dim i As Long, j As Long

Dim str As String
For i = 0 To Len(MyString)
str = str & Mid$(MyString, i + 1, 1) & vbNullChar
Next

i = 0
MyArr = Split(str, vbNullChar)
ReDim MyNewArr(0)
MyNewArr(0) = MyArr(0)

For i = LBound(MyArr) To UBound(MyArr)
bValue = True
For j = i + 1 To UBound(MyArr)
If MyArr(i) = MyArr(j) Then
bValue = False
Exit For
End If
Next
If bValue Then X = X & " " & MyArr(i)
Next
RemoveDuplicateLetter = X
Exit Function
vbErrorHandler:

End Function
 
Could you clarify what you are trying to do?

The way I understand what you are after is:
If you have a String: "[tt][blue]Letters in bookkeeping office[/blue][/tt]"
You want to remove duplicate letter next to each other to end up with: "[tt][blue]Leters in bokeping ofice[/blue][/tt]"

Is that correct [ponder]

Or, if you want to eliminate any duplicates no matter where they are, how about this:

Code:
Function RemoveDuplicateLetter(ByVal MyString As String) As String
Dim strOut As String
Dim i As Integer

For i = 1 To Len(MyString)
    If InStr(strOut, Mid(MyString, i, 1)) = 0 Then
        strOut = strOut & Mid(MyString, i, 1)
    End If
Next i

RemoveDuplicateLetter = strOut

End Function

---- Andy

There is a great need for a sarcasm font.
 
Or a regular expression, something like eg

Code:
[blue]    With New RegExp
        .Pattern = "(.)\1+"
        .Global = True
        Debug.Print .Replace("Letters in bookkeeping office", "$1")
    End With[/blue]
 
You don't even need code for this - a wildcard Find/Replace is all that's needed:
Find = ([A-Za-z])\1
Replace = \1
Of course, it can also be done with some Find/Replace code...

Cheers
Paul Edstein
[MS MVP - Word]
 
Which I took to mean 'a word', particularly since the first part of the OP's example code is involved in inserting such a delimiter into a word (or string) ...

Hopefully the OP will come back and let us know ...
 
Lalitha logged in only on July 23, 2020 to post this question, and - so far - never logged back in
We may never know the answer... :-(


---- Andy

There is a great need for a sarcasm font.
 
Crickets...

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top