我正在编写新颖的管理软件,我需要能够准确地跟踪richtextbox中的单词量。这是我到目前为止所拥有的
Dim Change As Integer
Dim Count As Integer
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
Change = RichTextBox1.Text.Split(" ").ToLookup(Function(x) x).Count()
'Add 1 to the variable Change every time the space bar is pressed
Count = Change
If RichTextBox1.Text = "" Then
Count = 0
'If the textbox is empty, the word count is 0
ElseIf RichTextBox1.Text.EndsWith(" ") = True Then
Count = Change - 1
'take one away from the wordcount variable when the last character is a space
End If
ToolStripStatusLabel2.Text = Count
'Display the wordcount
End Sub
如何让代码继续在多行上运行?到目前为止,代码只在第一行的文本上运行。如果用户按回车键然后继续输入,则字数不计算后续每行的第一个字