Home » Applications » Count number of charcters in a string – VB.NET

Count number of charcters in a string – VB.NET

Code Behind

Dim count As Integer = 0
Dim CharCount As String = "Today is sunny day"

For Each c As Char In CharCount
   If Char.IsLetter(c) Or Char.IsNumber(c) Then
        count += 1
    End If
 Next
LblCharCount.Text = "Total number of characters is "& count.ToString()

Markup Page

<asp:Label ID="LblCharCount" runat="server" /></asp:Label>