- Version
- Download 84
- File Size 63.12 KB
- File Count 1
- Create Date April 25, 2016
- Last Updated April 25, 2016
Visual Basic .Net Count Number of Characters in a String
Visual Basic .Net Count Number of Characters in a String
.length property is used to count the number of characters in a string. This is a sample program in vb.net that allows the user to enter a text and count the characters on it. Spaces are not counted.
Open the project solution (.sln) in visual studio 2010/2012 or open directly the project file (.vbproj)
Source code:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim trimspaces As String = TextBox1.Text
        trimspaces = trimspaces.Replace(" ", "")
        If TextBox1.Text = "" Then
            MessageBox.Show("Please enter a text.")
            TextBox1.Focus()
            Label2.Text = ""
        Else
            Label2.Text = "the number of characters in the text field: " & trimspaces.Length
        End If
    End Sub
End Class
        
 
							 
							