Solved

return word in string > 1

Posted on 2011-03-19
1
239 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 125 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now