VB2010(15)_一个简单的统计字符或单词数的应用程序

Public Class Form1
    '统计字符数的函数
    Private Function CountCharcters(ByVal text As String) As Integer
        Return text.Length
    End Function
    '统计单词数的函数
    Private Function CountWords(ByVal text As String) As Integer
        If text.Trim.Length = 0 Then Return 0
        Dim strWords() As String = text.Split(" "c)
        Return strWords.Length
    End Function
    '从文本框中获取文本并更新显示的子过程
    Private Sub UpdateDisplay()
        If radCountWords.Checked Then
            lblResults.Text = CountWords(txtWords.Text) & " words."
        Else
            lblResults.Text = CountCharcters(txtWords.Text) & " characters."
        End If
    End Sub
    '文本框事件
    Private Sub txtWords_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtWords.TextChanged
        UpdateDisplay()
    End Sub
    'radioButton事件
    Private Sub radCountWords_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radCountWords.CheckedChanged
        UpdateDisplay()
    End Sub
    'RadioButton事件
    Private Sub radCountChars_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radCountChars.CheckedChanged
        UpdateDisplay()
    End Sub

End Class
 

相关文章:

  • 2021-11-14
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2022-01-29
  • 2021-10-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案