count the same items in a listbox

  • 9 years ago

     Hi All,

    What I'm trying to do is to populate a listbox with the words of a richtextbox.

    Dim str As String = RichtextBox1.Text

    This works, but it also add's the same words.

    How can I count the same words.
    For example:

    I like VB.Net very much.
    But sometimes VB.Net doesn't like me.

    The listbox should give me:

    I (1)
    like (2)
    VB.Net (2)

    That's what I have so far, however it could be totally wrong:

    Dim element As String = Richtextbox1.Text
    If Not ListBox1.Items.Contains(element) Then
    ...... count the same words
    End If
    How can I do that?

    Thanks in advance,
  • 9 years ago

    I would suggest breaking the  Richtextbox1.Text down into single words and then add to listbox (checking it beforehand).

    Dim element() as string

    Dim i as integer 

    element = Richtextbox1.Text.Split(" ")

    For i=0 to element.Count - 1

        If Not ListBox1.Items.Countains(element(i)) Then


       End If

    Next i 


    or something similar.




Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”