IT KNOWLEDGE

IT KNOWLEDGE
BC

Thursday, May 22, 2014

Find How Many Times One Word Occur in Paragraph or Content

Below is the sample code for finding how many time which one word or string occur in paragraph or content. I use one Textbox to store whole text and another one Textbox for input word that we want to find by using ButtonClike_Event.

Application Design
No Control Type Name Text
1 TextBox1 TextBoxWholeString
2 TextBox2 TextBoxFind
3 Button1 ButtonFind Find
4 Label1 LabelShow

Code
Public Class StringOccur
    Private Function FindWords(ByVal TextSearched As String, ByVal Paragraph As String) As Integer
            Dim location As Integer = 0
            Dim occurances As Integer = 0
            Do
                location = TextSearched.IndexOf(Paragraph, location)
                If location <> -1 Then
                    occurances += 1
                    location += Paragraph.Length

                End If
            Loop Until location = -1
            Return occurances
    End Function
    Private Sub ButtonFind_Click(sender As Object, e As EventArgs) Handles ButtonFind.Click
        Try
            LabelShow.Text = "The word " & TextBoxFind.Text & " has occured " & FindWords(TextBoxWholeString.Text, TextBoxFind.Text) & " times!!"
        Catch ex As Exception

        End Try
        End Sub
End Class















Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: itech-9999

0 comments: