|
-
May 19th, 2010, 09:26 PM
#1
Thread Starter
Addicted Member
[RESOLVED] How to display duplicate string in text box?
Dear all expert programmers,
Please tell me how to hightlight duplicate string in text box. Please see example below
Sample1 :
Cat Bat Mat Eat Cow Start Begin Cat
Duplicate string is Cat
Sample2 :
Cat Bat Cow Mat Eat Cow Start Begin Cat
Duplicate string is Cat, Cow
Thank you for all answers.
-
May 19th, 2010, 09:34 PM
#2
Re: How to display duplicate string in text box?
Use Split function to split the string into an array, then loop through it to find duplicates.
-
May 19th, 2010, 09:50 PM
#3
Frenzied Member
Re: How to display duplicate string in text box?
Here's a HORRIBLE way to do it:
Code:
Private Function ListDupes(str As String) As String
Dim sS() As String, x As Long, dupe As String, wow As String
sS = Split(str & " ")
For x = 0 To UBound(sS) - 1
If InStrB(1, dupe, ", " & sS(x)) > 0 Then
wow = wow & ", " & sS(x)
End If
dupe = dupe & ", " & sS(x)
Next x
If LenB(wow) > 0 Then
wow = Mid$(wow, 3)
End If
ListDupes = wow
End function
-
May 19th, 2010, 10:17 PM
#4
Re: How to display duplicate string in text box?
Adding a bit to what baja_yu suggested: Split, sort and loop through. Sorting makes it easier to find the duplicates, because the same ones are in a group, so you don't need to loop through all other items for each item to find the duplicates.
Here is something that isn't often suggested: Filter.
Code:
Option Explicit
Private Sub Form_Load()
Dim strArray() As String, lngUB As Long, strRemove As String
strArray = Split("Cat Bat Cow Mat Eat Cow Start Begin Cat")
Do While UBound(strArray) > 0
lngUB = UBound(strArray)
strRemove = strArray(0)
strArray = Filter(strArray, strRemove, False)
If UBound(strArray) + 1 < lngUB Then Debug.Print strRemove
Loop
End Sub
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
|