here's my example using regex + LINQ. it also uses an rtb, a button + a textbox (txtFind):
vb Code:
Imports System.Text.RegularExpressions Public Class Form1 Private Structure word Dim count As Integer Dim percentage As Decimal End Structure Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim words() As String = Regex.Split(RichTextBox1.Text, "\s|\,\s?|\.\s?|\;\s?|\:\s?|$") Dim wordDictionary As Dictionary(Of String, word) = (From w In words.Where(Function(s) s.Trim <> "").Distinct _ Select New With { _ .word = w, _ .count = words.Count(Function(s) w.ToLower = s.ToLower), _ .percentage = (.count * 100) / words.Where(Function(s) s.Trim <> "").Count}). _ ToDictionary(Function(kvp) kvp.word, Function(kvp) New word With _ {.count = kvp.count, .percentage = kvp.percentage}) If wordDictionary.Keys.Contains(txtFind.Text) Then _ MsgBox(String.Format("Word: {0}, occurences {1}%", txtFind.Text, wordDictionary(txtFind.Text).percentage)) End Sub End Class




Reply With Quote