?
Solved

return word in string > 1

Posted on 2011-03-19
1
Medium Priority
?
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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