How To Count Specific Character Occurrence In A String Using Visual Basic.Net
In This VB.Net Tutorial We Will See How To Count The Number Of Selected Char Occurrences In A TextBox Text Using Visual Basic.Net Programming Language And Visual Studio Editor.
Project Source Code:
Public Class FormCharOccurrence
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim txt As String
txt = TextBox1.Text
Dim occurrence As Integer
occurrence = 0
For i As Integer = 0 To txt.Length - 1
If txt(i) = TextBox2.Text.ToCharArray()(0) Then
occurrence += 1
End If
Next
MsgBox(occurrence)
End Sub
End Class
///////////////OUTPUT:
Download Projects Source Code