|
-
Dec 9th, 2007, 08:48 PM
#1
Thread Starter
Addicted Member
[RESOLVED] How to get duplicate character?
Dear all expert programmer,
I want to know how to get duplicate character in data. If I have data below.
tmpStr = "abcd,bcde,cdef,dehmo"
Duplicate character is "d" but I can't code it. Please tell me how to get duplicate character.
Thank you for all post.
-
Dec 9th, 2007, 08:53 PM
#2
Re: How to get duplicate character?
Isn't "e" (and others) also duplicate?
-
Dec 9th, 2007, 08:57 PM
#3
Thread Starter
Addicted Member
Re: How to get duplicate character?
tmpStr = "abcd,bcde,cdef,dehmo"
"d" is duplicate because you can see it in all group (seperate group by ,), If you can not see it in all group it is not duplicate.
-
Dec 9th, 2007, 10:21 PM
#4
Re: How to get duplicate character?
Code:
Const TEST_DATA = "abcd,bcde,cdef,dehmo"
Dim strParts() As String
Dim lngNdxOfString1 As Long
Dim lngNdxOfRest As Long
Dim bInAll As Boolean
Dim strTemp As String
strParts = Split(TEST_DATA, ",")
For lngNdxOfString1 = 1 To Len(strParts(0))
bInAll = True
For lngNdxOfRest = 1 To UBound(strParts)
strTemp = Replace(strParts(lngNdxOfRest), Mid$(strParts(0), lngNdxOfString1, 1), "")
If Len(strTemp) = Len(strParts(lngNdxOfRest)) Then
bInAll = False
Exit For
End If
Next
If bInAll Then
MsgBox Mid$(strParts(0), lngNdxOfString1, 1) & " is duplicate"
End If
Next
-
Dec 10th, 2007, 12:30 AM
#5
Thread Starter
Addicted Member
Re: How to get duplicate character?
Please test modified code and help me again.
vb Code:
Private Function GetDuplicatechar(ByVal strSource As String) As String
Dim strParts() As String
Dim lngNdxOfString1 As Long
Dim lngNdxOfRest As Long
Dim bInAll As Boolean
Dim strTemp As String
Dim strResultX As String
strParts = Split(strSource, ",")
strResultX = ""
For lngNdxOfString1 = 1 To Len(strParts(0))
bInAll = True
For lngNdxOfRest = 1 To UBound(strParts)
strTemp = Replace(strParts(lngNdxOfRest), Mid$(strParts(0), lngNdxOfString1, 1), "")
If Len(strTemp) = Len(strParts(lngNdxOfRest)) Then
bInAll = False
Exit For
End If
Next
If bInAll Then
strResultX = Mid$(strParts(0), lngNdxOfString1, 1)
End If
Next
GetDuplicatechar = strResultX
End Function
Private Sub Command1_Click()
MsgBox GetDuplicatechar("4582,4582") 'It will show 4582
End Sub
Last edited by standardusr; Dec 10th, 2007 at 12:35 AM.
-
Dec 10th, 2007, 12:51 AM
#6
Re: How to get duplicate character?
Change the highlighted part.
Code:
If bInAll Then
strResultX = strResultX & Mid$(strParts(0), lngNdxOfString1, 1)
End If
-
Dec 10th, 2007, 01:18 AM
#7
Thread Starter
Addicted Member
Re: How to get duplicate character?
Thank you.
If the code is
vb Code:
Private Sub Command1_Click()
MsgBox GetDuplicatechar("4582,")
End Sub
Why it is empty string?
-
Dec 10th, 2007, 01:20 AM
#8
Re: How to get duplicate character?
Because there is no duplicate.
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
|