Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the IsNullorWhitSpace() method of String class
By Nidhi Last Updated : November 11, 2024
String.IsNullorWhitSpace() Method in VB.Net
The IsNullorWhitSpace() method is used to check the specified string contains null or only whitespace.
Syntax
Function IsNullorWhitSpace(ByVal str as String) as Boolean
Parameter(s)
- Str: Specified string to be checked.
Return Value
It returns the Boolean value, it returns true when the specified string contains null or only whitespace. Otherwise, it will return false.
VB.Net code to demonstrate the example of String.IsNullorWhitSpace() method
The source code to demonstrate the IsNullorWhitSpace() method of the String class is given below. The given program is compiled and executed successfully.
'VB.NET program to demonstrate the IsNullOrWhiteSpace() method
'of String class.
Imports System
Module Module1
Sub Main()
Dim str1 As String = " "
Dim str2 As String = "Hello World"
Dim ret As Boolean
ret = String.IsNullOrWhiteSpace(str1)
If ret = True Then
Console.WriteLine("Strings str1 contains Null or only Whitespace")
Else
Console.WriteLine("Strings str1 does not contain Null or only Whitespace")
End If
ret = String.IsNullOrWhiteSpace(str2)
If ret = True Then
Console.WriteLine("Strings str2 contains Null or only Whitespace")
Else
Console.WriteLine("Strings str2 does not contain Null or only Whitespace")
End If
End Sub
End Module
Output
Strings str1 contains Null or only Whitespace
Strings str2 does not contain Null or only Whitespace
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.
In the Main() function, we created two strings str1 and str2. Here, we check the string contains null or only whitespace using the IsNullOrWhiteSpace() method of String class and then printed the appropriate message on the console screen.
VB.Net String Programs »