MATH000 MATH000 - 2 years ago 200 Question

Visual Basic .NET Empty/Null String difference?

I would like to differentiate between


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

Ian Ian
Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download