0

I want to count the spaces for every space existence in the text-field.

This is my function:

  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
user2751035
  • 93
  • 1
  • 3
  • 12

3 Answers3

0

I suppose you want to count the occurrences of the space character inside a given string. According to this you could use a LINQ.

value.Count(Function(c) c = " "c)

Hope I helped!

Community
  • 1
  • 1
Pantelis Natsiavas
  • 5,293
  • 5
  • 21
  • 36
0
 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
senthilkumar2185
  • 2,536
  • 3
  • 22
  • 36
0
Dim spacescount as Integer = 0
For Each character as Char in RichTextBox1.Text
    If character = " " then
        spacescount +=1
    End If
Next
matthew
  • 3
  • 1