VB6 和 VB.net 中的 IsNull

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19288584/
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 15:25:51  来源:igfitidea点击:

IsNull in VB6 and VB.net

vb.netvb6migrationisnull

提问by nnnn

I have a code -

我有一个代码 -

strTest="    "    
IsNull(Trim(strTest)) 

It returns Falsein VB6 .

I write this code to VB.net but

它在 VB6 中返回False

我将此代码写入 VB.net 但

IsNull(Trim(strTest))

IsNull(Trim(strTest))

returns True.
So, IsNull(Trim(" "))in VB6 = ??in VB.net
Thank you.

返回True
所以, VB6 中的IsNull(Trim(" "))= ?? 在 VB.net
谢谢。

回答by Siddharth Rout

There is no IsNullfunction in VB.Net. Instead it has other things like String.IsNullOrEmptyfunction and String.Emptyproperty etc. for finding out whether a string is empty or not.

IsNullVB.Net 中没有函数。相反,它具有其他String.IsNullOrEmpty功能,如函数和String.Empty属性等,用于确定字符串是否为空。

IsNullin VB6/VBA means whether an expression contains no valid data. You are getting Falsein vb6 because you have initialized strTest. It holds an empty string. You might also want to see THIS

IsNull在 VB6/VBA 中表示表达式是否包含无效数据。您进入Falsevb6 是因为您已经初始化了strTest. 它包含一个空字符串。你可能还想看这个

VB6

VB6

IsNull(Trim(strTest)) 

In VB.Net, IsNullOrEmptyIndicates whether the specified string is Nothingor an Emptystring.

在 VB.Net 中,IsNullOrEmpty指示指定的字符串是Nothing还是Empty字符串。

VB.NET

网络

If String.IsNullOrEmpty(strTest.Trim) Then DoWhatever
If strTest.Trim = String.Empty Then DoWhatever
If strTest.Trim = "" Then DoWhatever      '<~~ Same in VB6 as well
If String.IsNullOrWhiteSpace(strTest) Then DoWhatever  '<~~ VB2010 onwards only

All these will return Truein VB.Net because the string ISEMPTY. You might want to see THIS

所有这些都将True在 VB.Net 中返回,因为字符串ISEMPTY。你可能想看这个

If your string value is all spaces then either use strTest.Trim()before using the first 3 options, or use the 4th option directly which checks whether it is nothing, or empty string or all spaces only.

如果您的字符串值全是空格,那么要么strTest.Trim()在使用前 3 个选项之前使用,要么直接使用第 4 个选项来检查它是空字符串还是空字符串或仅所有空格。