×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

Could you clarify what you are trying to do?

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

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.

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

Or a regular expression, something like eg

CODE

    With New RegExp
        .Pattern = "(.)\1+"
        .Global = True
        Debug.Print .Replace("Letters in bookkeeping office", "$1")
    End With 

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

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]

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

Does that not presuppose we are working in Word?

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

That's what I understood from

Quote:

When there is no Delimiter in word

Cheers
Paul Edstein
[MS MVP - Word]

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

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 ...

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

Or not, as the case may be ...

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

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... sad


---- Andy

There is a great need for a sarcasm font.

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

Crickets...

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close