Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use IsNullOrEmpty in VB.NET?

Why doesn't the following compile in VB.NET?

Dim strTest As String
If (strTest.IsNullOrEmpty) Then
   MessageBox.Show("NULL OR EMPTY")
End if
like image 501
CJ7 Avatar asked Oct 30 '12 07:10

CJ7


People also ask

How do I check if a string is empty?

The isEmpty() method checks whether a string is empty or not. This method returns true if the string is empty (length() is 0), and false if not.

What is string IsNullOrEmpty?

In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A string will be null if it has not been assigned a value. A string will be empty if it is assigned “” or String. Empty (A constant for empty strings).

Is null in VB?

The Null value indicates that the Variant contains no valid data. Null is not the same as Empty, which indicates that a variable has not yet been initialized. It's also not the same as a zero-length string (""), which is sometimes referred to as a null string.


2 Answers

IsNullOrEmpty is 'shared' so you should use it that way:

If String.IsNullOrEmpty(strTest) Then
like image 191
Tomq Avatar answered Sep 28 '22 10:09

Tomq


You can actually just compare to an empty string:

If strTest = "" Then
    MessageBox.Show("NULL OR EMPTY")
End If
like image 23
Rolf Bjarne Kvinge Avatar answered Sep 28 '22 10:09

Rolf Bjarne Kvinge