VB.Net program to demonstrate the Empty property of String class

Here, we are going to demonstrate the Empty property of String class in VB.Net.
Submitted by Nidhi, on January 20, 2021 [Last updated : March 07, 2023]

String.Empty Property in VB.Net

The Empty property is used to represent the empty string in VB.Net.

Syntax

String.Empty as String

VB.Net code to demonstrate the example of String.Empty property

The source code to demonstrate the Empty property of the String class is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the Empty property 
'of String class.

Imports System

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

        If (str1 = String.Empty) Then
            Console.WriteLine("String str1 is empty")
        Else
            Console.WriteLine("String str1 is not empty")
        End If

        If (str2 = String.Empty) Then
            Console.WriteLine("String str2 is empty")
        Else
            Console.WriteLine("String str2 is not empty")
        End If
    End Sub
End Module

Output

String str1 is empty
String 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, str1 is an empty string whereas str2 contains some string value. Here, we check the emptiness of both strings one by one and print the appropriate message on the console screen.

VB.Net String Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.