VB.Net program to check string contains a number or not

Here, we are going to learn how to check string contains a number or not in VB.Net?
Submitted by Nidhi, on January 07, 2021

Here, we will use IsNumeric() function to check a string contains a number or not.

Program/Source Code:

The source code to check string contains a number or not is given below. The given program is compiled and executed successfully.

'Vb.Net program to check a string contains a number or not.

Module Module1
    Sub Main()
        Dim num As String = "123"
        Dim ret As Boolean

        ret = IsNumeric(num)

        If (ret = True) Then
            Console.WriteLine("Specified string contains a number")
        Else
            Console.WriteLine("Specified string does not contain a number")
        End If
    End Sub
End Module

Output:

Specified string contains a number
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a Main() function.

The Main() function is the entry point for the program. Here, we created a variable of string type which is initialized with "123", and then check the value of the string, it contains a number or not using IsNumeric() function and then print an appropriate message on the console screen.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.