safary
safary

Reputation: 325

Need to check for empty string, visual basic

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

Answers (1)

Cal.B
Cal.B

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

Related Questions