vb.net 需要检查空字符串,visual basic

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41548175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:09:53  来源:igfitidea点击:

Need to check for empty string, visual basic

vb.net

提问by safary

Can someone help me to write a code that checks if string is empty and returns null if its true?

有人可以帮我写一个代码来检查字符串是否为空,如果为真则返回 null 吗?

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.

但它只检查 role_desc 是否为空,但我还需要检查它的值是否不是空字符串,如果是,则返回 null。

回答by Cal.B

What taquion said, or IsNullOrWhiteSpace. Looks like:

什么taquion说,或IsNullOrWhiteSpace。好像:

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