VB.NET tutorial-Count number of digits in string

String Manipulation

Count number of digits in string

The Char structure type provides a method called IsDigit(char c) to see whether a character in a string is a digit. This method takes only one argument. The argument is the character that you want to check. In the example below, we use IsDigit(char c) method to count the number of digits in a string "ID123223";

If you want to indicate whether a character in a specified position of a string is a digit, you can use IsDigit(string st, int position) method.

Example:

Module Module1

Sub Main()

Dim name As String Console.Write("Enter your name:") name = Console.ReadLine() If Char.IsDigit(name, 0) Then Console.Write("The name can't be started with a digit.") Else : Console.WriteLine("Wecome " & name) End If Console.ReadLine()

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.