Solved

return word in string > 1

Posted on 2011-03-19
1
274 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 125 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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