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

Vb.net 需要检查空字符串,visual basic,vb.net,Vb.net,有人能帮我写一个代码来检查字符串是否为空,如果为真则返回null吗 我现在有: If(Not IsNothing(role.ROLE_DESC),role.ROLE_DESC.ToString(),Nothing) 但它只检查role_desc是否为null,但我还需要检查它的值是否不是空字符串,如果是,则返回null。taquion所说的,或者IsNullOrWhiteSpace。 看起来像: If TypeOf role.ROLE_DESC Is String AndAlso String

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

我现在有:

If(Not IsNothing(role.ROLE_DESC),role.ROLE_DESC.ToString(),Nothing)

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

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

塔奎恩所说的,或者
是空的或者空白的。
看起来像:

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

尝试使用string.IsNullOrEmpty函数检查此尝试使用string.IsNullOrEmpty函数检查此假设
角色。角色\u DESC
是一个字符串,
IsNullOrEmpty
也是
IsNullOrWhiteSpace
的子集,因此第一个检查几乎是冗余的!使用
AndAlso
而不是分成两行。哈,这太挑剔了!但是你没有错。假设
role.role_DESC
是一个字符串,
IsNullOrEmpty
IsNullOrWhiteSpace
的子集,所以第一个检查几乎是多余的!使用
AndAlso
而不是分成两行。哈,这太挑剔了!不过你没有错。