?
Solved

return word in string > 1

Posted on 2011-03-19
1
Medium Priority
?
289 Views
Last Modified: 2012-06-27
How can I find out if a string contain words more than one time? Sample: one, two, three, four, five, two, one,six,seven, etc<br /><br />Result <br />One and two
0
Comment
Question by:VBdotnet2005
1 Comment
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35173723
Hi,

According to your String Example, you can do it with the code below

Hope that helps
Dim strSample As String = "one, two, three, four, five, two, one,six,seven"
        Dim alCountWords As New ArrayList
        Dim htTimes As New Hashtable
        Dim vecWords() As String
        Dim intWord As Integer
        Dim strWord As String

        vecWords = strSample.Split(",")
        For intWord = 0 To vecWords.Length - 1
            strWord = vecWords(intWord).Trim
            If alCountWords.Contains(strWord) Then
                htTimes(strWord) = Int32.Parse(htTimes(strWord).ToString) + 1
            Else
                htTimes.Add(strWord, 1)
                alCountWords.Add(strWord)
            End If
        Next

        Dim strResults As String = ""
        For intWord = 0 To alCountWords.Count - 1
            If htTimes(alCountWords(intWord)) > 1 Then
                strResults &= alCountWords(intWord) & ","
            End If
        Next

        MsgBox(strResults)

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question