2

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.

2

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

3 Comments

Presumes that role.ROLE_DESC is a string, also, IsNullOrEmpty is a subset of IsNullOrWhiteSpace , so the first check is redundant
Almost there! Use AndAlso instead of splitting over two lines.
Ha, now that's just picky! You're not wrong though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.