Public Class Form1
Dim nwordcount As Integer
Dim ncharcount As Integer
Dim nspacecount As Integer
Dim nsentencecount As Integer
Public Sub btnAnalyze_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnalyze.Click
Dim strMaterial As String = txtMaterial.Text
ncharcount = GetCharacterCount(strMaterial)
nsentencecount = GetSentenceCount(strMaterial)
nspacecount = GetSpaceCount(strMaterial)
nwordcount = GetWordCount(strMaterial)
RefreshTextboxes()
End Sub
Private Function GetCharacterCount(ByVal str As String) As Integer
Return str.Length
End Function
Private Function GetSentenceCount(ByVal str As String) As Integer
Dim counter As Integer = 0
For Each ending As String In str
If ending.Contains(".") Or ending.Contains("?") Or ending.Contains("!") Then
counter += 1
End If
Next
Return counter
End Function
Private Function GetSpaceCount(ByRef str As String) As Integer
Dim counter As Integer = 0
For Each Space As String In str
If Space.Contains(" ") Then
counter += 1
End If
Next
Return counter
End Function
Private Function GetWordCount(ByRef str As String) As Integer
Dim counter As Integer = System.Text.RegularExpressions.Regex.Matches(str, "\S+").Count
Return counter
End Function
Public Sub RefreshTextboxes()
txtCharacters.Text = ncharcount
txtSentences.Text = nsentencecount
txtSpaces.Text = nspacecount
txtWords.Text = nwordcount
End Sub
End Class
Friday, May 6, 2011
Methods 1 - Text Analyzer
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment