我想为文本字段中存在的每个空间计算空间。
这是我的功能:
Private Sub btncntspace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncntspace.Click
txtcountspace.Text = txttyping.Text.Length(" ").ToString
End Sub
我想您想计算给定字符串中空格字符的出现次数。根据这个,你可以使用LINQ。
value.Count(Function(c) c = " "c)
希望我能帮上忙!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnt As Int32 = 0
If RichTextBox1.TextLength > 0 Then
For i = 0 To RichTextBox1.TextLength - 1
If String.IsNullOrWhiteSpace(RichTextBox1.Text(i).ToString()) Then
cnt = cnt + 1
MsgBox(cnt.ToString())
End If
Next
End If
End Sub
Dim spacescount as Integer = 0
For Each character as Char in RichTextBox1.Text
If character = " " then
spacescount +=1
End If
Next