Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

find duplicate words

How can I find out if a string contains same words?


dim mystring as string = "Accountnumber, address, zipcode, accountnumber, phonenumber, address, workphone"


result would be Accountnumber and  address
Avatar of kaufmed
kaufmed
Flag of United States of America image

Try this:
Imports System.Text.RegularExpressions

...


Dim mystring As String = "Accountnumber, address, zipcode, accountnumber, phonenumber, address, workphone"
Dim matches As String = Regex.Matches(mystring.ToLower(), "([a-z]+).*?\1")

For Each m As Match In matches
    Console.WriteLine(m.Value)
Next

Open in new window

Avatar of VBdotnet2005

ASKER

Dim mystring As String = "Accountnumber, address, zipcode, accountnumber, phonenumber, address, workphone"
Dim matches As String = Regex.Matches(mystring.ToLower(), "([a-z]+).*?\1")    <<<<< error

For Each m As Match In matches
    Console.WriteLine(m.Value)
Next
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial