Home »
        VB.Net »
        VB.Net Programs
    
    VB.Net program to check string contains a number or not
    
    
    
    
	    
		    By Nidhi Last Updated : October 13, 2024
	    
    
    
    Checking whether a string contains a number or not in VB.Net
    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 code to check string contains a number or not
'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.
    VB.Net String Programs »
    
    
    
    
    
   
    
  
    Advertisement
    
    
    
  
  
    Advertisement