Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strCharacters, strWords, strSentences, strSpaces As String strCharacters = TextBox1.Text Dim strCharactersCounted = getCharacters(strCharacters) TextBox2.Text = strCharactersCounted strWords = TextBox1.Text Dim strWordsCounted = getWordCount(strWords) TextBox3.Text = strWordsCounted strSentences = TextBox1.Text Dim strSentencesCounted = getSentencesCount(strSentences) TextBox4.Text = getSentencesCount(strSentences) strSpaces = TextBox1.Text Dim strSpacesCounted = getSpacesCount(strSpaces) TextBox5.Text = getSpacesCount(strSpaces) End Sub Private Function getCharacters(ByVal strCharacters As String) Return strCharacters.Length End Function Private Function getWordCount(ByVal InputString As String) As Integer Return Split(System.Text.RegularExpressions.Regex.Replace(InputString, "\s+", Space(1))).Length End Function Private Function getSentencesCount(ByVal strSentences As String) Dim maxCount As Integer = strSentences.Length Dim intSent As Integer = 0 For Each singleChar As String In strSentences If singleChar = "." Or singleChar = "?" Or singleChar = "!" Then intSent += 1 End If Next Return intSent End Function Private Function getSpacesCount(ByVal strSpaces As String) Dim maxCount As Integer = strSpaces.Length Dim intSent As Integer = 0 For Each singleChar As String In strSpaces If singleChar = " " Then intSent += 1 End If Next Return intSent End Function End Class
Monday, April 11, 2011
Programming 2 */ Methods */
Subscribe to:
Post Comments (Atom)
Classes
Programming II
Advanced Relational Database
No comments:
Post a Comment