|
-
Apr 12th, 2011, 03:26 AM
#1
Thread Starter
Addicted Member
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.
Last edited by standardusr; Apr 12th, 2011 at 06:19 PM.
-
Apr 12th, 2011, 08:00 AM
#2
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
-
Apr 12th, 2011, 08:08 AM
#3
Member
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.
Thinking And Saying Java is great because it works on All operating Systems is same as saying Anal is good because it works on all genders - By Arslan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|