ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate the IsNullorEmpty() method of String class

Here, we are going to demonstrate the IsNullorEmpty() method of String class in VB.Net.
Submitted by Nidhi, on January 20, 2021

The IsNullorEmpty() method is used to check the specified string is empty or not.

Syntax:

Function IsNullorEmpty(ByVal str as String) as Boolean

Parameters:

  • Str: Specified string to check the emptiness.

Return Value: It returns the Boolean value, it returns true when the specified string is empty. Otherwise, it will return false.

Program/Source Code:

The source code to demonstrate the IsNullorEmpty() method of the String class is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the IsNullorEmpty() 
'method of String class.

Imports System

Module Module1
    Sub Main()
        Dim str1 As String = Nothing
        Dim str2 As String = "Hello World"
        Dim ret As Boolean

        ret = String.IsNullOrEmpty(str1)

        If ret = True Then
            Console.WriteLine("Strings str1 is empty")
        Else
            Console.WriteLine("Strings str1 is not empty")
        End If

        ret = String.IsNullOrEmpty(str2)
        If ret = True Then
            Console.WriteLine("Strings str2 is empty")
        Else
            Console.WriteLine("Strings str2 is not empty")
        End If
    End Sub
End Module

Output:

Strings str1 is empty
Strings str2 is not empty
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 emptiness of strings using the IsNullorEmpty() method of the String class and then printed the appropriate message on the console screen.

VB.Net String Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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.