Wednesday, April 13, 2011

Practice # 6

1:  Public Class Form1  
2:    Dim nWord As Integer  
3:    Dim nCharacter As Integer  
4:    Dim nSentence As Integer  
5:    Dim nSpace As Integer  
6:    Private Sub Analyze_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Analyze.Click  
7:      Dim str As String = txtPar.Text  
8:      nWord = WordCount(str)  
9:      nCharacter = CharacterCount(str)  
10:      nSentence = SentenceCount(str)  
11:      nSpace = SpaceCount(str)  
12:      Answer()  
13:    End Sub  
14:    Private Function CharacterCount(ByVal str As String) As Integer  
15:      Return str.Length  
16:    End Function  
17:    Public Function WordCount(ByVal value As String) As Integer  
18:      Return System.Text.RegularExpressions.Regex.Matches(value, "\S+").Count()  
19:    End Function  
20:    Public Function SentenceCount(ByVal sentence As String) As Integer  
21:      Dim x As Integer  
22:      x = sentence.Split(".").Count()  
23:      x -= 1  
24:      Return x  
25:    End Function  
26:    Public Function SpaceCount(ByVal space As String) As Integer  
27:      Dim x As Integer  
28:      x = space.Split(" ").Count()  
29:      x -= 1  
30:      Return x  
31:    End Function  
32:    Private Sub Answer()  
33:      txtWords.Text = nWord  
34:      txtCharacters.Text = nCharacter  
35:      txtSentences.Text = nSentence  
36:      txtSpaces.Text = nSpace  
37:    End Sub  
38:  End Class  

No comments:

Post a Comment