[2005] count the same items in a listbox
Hi All,
What I'm trying to do is to populate a listbox with all the words in a richtextbox
Code:
Dim str As String = RichtextBox1.Text
Listbox1.Items.Add(str)
This works, but it also add's the same words(items).
How can I count the same words(items).
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)
etc.....
That's what I have so far:
Code:
Dim element As String = Richtextbox1.Text
If Not ListBox1.Items.Contains(element) Then
ListBox.Items.Add(element)
else
...... count the same words
End If
How can I do that?
Thanks in advance,
sparrow1
Re: [2005] count the same items in a listbox
vb Code:
Dim i As Integer = 0
For Each Str As String In ListBox1.Items
If Str = "what ever string here" Then
i = i + 1
End If
Next
MsgBox(i.ToString())
Re: [2005] count the same items in a listbox
Use a Dictionary(Of String, Integer). The words are the keys and the counts are the values.