Public Class Form1
Public Function getWordCount(ByVal InputString As String) As Integer
Return Split(System.Text.RegularExpressions.Regex.Replace(InputString, "\s+", Space(1))).Length
End Function
Public Function getSentenceCount(ByVal InputString As String) As Integer
Dim nperiod As Integer
Dim nexclamation As Integer
Dim nquestion As Integer
nperiod = InputString.Split(".").Length
nexclamation = InputString.Split("!").Length
nquestion = InputString.Split("?").Length
Return (nquestion + nexclamation + nperiod)
End Function
Public Function CountSpaces(ByVal sText As String) As Long
Dim nSpaces As Integer = 0
For Each s As String In sText
If s = " " Then
nSpaces += 1
End If
Next
Return nSpaces
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = TextBox1.Text.Length
TextBox3.Text = getWordCount(TextBox1.Text)
TextBox4.Text = getSentenceCount(TextBox1.Text)
TextBox5.Text = CountSpaces(TextBox1.Text)
End Sub
End Class
Fun
Monday, April 11, 2011
counter
Labels:
vb.net
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment