Reputation: 325
Can someone help me to write a code that checks if string is empty and returns null if its true?
I have this now:
If(Not IsNothing(role.ROLE_DESC),role.ROLE_DESC.ToString(),Nothing)
But it only checks if role_desc is null, but I need to also check if its value is not an empty string and if so, then return null.
Upvotes: 2
Views: 13968
Reputation: 88
What taquion said, or IsNullOrWhiteSpace
.
Looks like:
If TypeOf role.ROLE_DESC Is String AndAlso String.IsNullOrEmpty(role.ROLE_DESC) OrElse String.IsNullOrWhiteSpace(role.ROLE_DESC) Then
'It is empty or whitespace
Else
'it isn't empty or whitespace
End If
Upvotes: 4