Visual Basic .Net Count Number of Characters in a String

Download
Download is available until [expire_date]
  • Version
  • Download 82
  • 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
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.