Please help me for search data which duplication with one character.
Dear all expert programmers,
If I have data below
ABC,ABD,DEF,FHI,FJK,ZXV,VTU,MNO
Result
1. ABD, DEF <-- Duplicate D only
2. DEF,FHI,FJK <-- Duplicate F only
3. ZXV, VTU <-- Duplicate V only
I want result above but I don't know how to create function to get this result. Please help me for this job. (If dup more than 1 character will be ignore)
Thank you for all posts.
Re: Please help me for search data which duplication with one character.
What about ABC,ABD - dup A and dup B
Seems pointless, but
Code:
Option Explicit
Private Sub EnumDupes(Str As String)
Dim a() As String
Dim Ltr As String
Dim i As Long
Dim j As Long
a = Split(Str, ",")
For i = 1 To UBound(a)
For j = 1 To 3
Ltr = Mid$(a(i), j, 1)
If InStr(a(i - 1), Ltr) Then
Debug.Print a(i), a(i - 1), Ltr
End If
Next
Next
End Sub
Private Sub Form_Load()
EnumDupes "ABC,ABD,DEF,FHI,FJK,ZXV,VTU,MNO"
End Sub
Re: Please help me for search data which duplication with one character.
Yes, As VBClassicRocks Replied, your question is limited only to handling two occurrences of a letter.
As implied in the logic, you split (or break) the given string at each space (or commas) to separate words and then iterating from current position to length of word, to find out if duplicates exists. Since you're counting whether two occurrences of a letter in a word, the complexity is limited to two for-loops, As you increase the count of occurances, the complexity increases in this manner.
Though, you can also search for duplicate occurrences using switch cases in a string (like CASE "AA" , CASE "BB", etc. ) in a string in a similar way. (Though you should follow this approach for smaller projects only.)
I hope it helps. :rolleyes: