MATH000 MATH000 - 7 months ago 44
Vb.net Question

Visual Basic .NET Empty/Null String difference?

I would like to differentiate between

NULL
and
""
.

How do I determine with an if statement if a String is NULL or ""?

Ian Ian
Answer

Nothing is when the string variable has no instance it refers to at all while "" is when the string variable has something it refers to and it is an empty string.

To distinguish, you could put the following conditions:

Dim s As String

If s Is Nothing Then 'It means it is Nothing

End If

If s = "" Then 'It means it points to some instance whose value is empty string

End If

VB.Net also has String.Empty which is equivalent to "":

If s = String.Empty Then

End If