Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET missing isNull()?

Tags:

vb.net

I like to confirm that array is created, how can it be done? There is no nul keyword?

Dim items As Array = str.Split("|")
if (items=null)  then ???
like image 548
Tom Avatar asked Mar 13 '09 12:03

Tom


2 Answers

To check if an object is null in VB.Net you need to use the Nothing keyword. e.g.

If (items is Nothing) Then
    'do stuff
End If

However string.Split() never returns null, so you should check the input string for null rather than the items array. Your code could be changed to something like:

If Not String.IsNullOrEmpty(str) Then
    Dim items As Array = str.Split("|")
    'do stuff
End If
like image 150
Matthew Dresser Avatar answered Oct 03 '22 09:10

Matthew Dresser


Try using String.IsNullOrEmpty on your string variable before splitting it. If you attempt to split the variable with nothing in the string the array will still have one item in it (an empty string), therefore your IsNothing checks on the array will return false.

like image 28
KevB Avatar answered Oct 03 '22 07:10

KevB