如果不是String.Empty忽略空字符串-VB.NET
我有一个字符串数组,我正在遍历它们,但是字符串可能是空的,所以我尝试以下方法:如果不是String.Empty忽略空字符串-VB.NET,vb.net,arrays,string,Vb.net,Arrays,String,我有一个字符串数组,我正在遍历它们,但是字符串可能是空的,所以我尝试以下方法: For Each Component As String In Components If Component IsNot String.Empty Then 'Work your magic End If Next 但如果组件是空字符串,则逻辑仍会激发。我也试过了 If Component <> "" Then End If 如果组件为“”,则 如果结束 同样的
For Each Component As String In Components
If Component IsNot String.Empty Then
'Work your magic
End If
Next
但如果组件是空字符串,则逻辑仍会激发。我也试过了
If Component <> "" Then
End If
如果组件为“”,则
如果结束
同样的结果。那么我错过了什么
string
Sub Main
Dim foo As String
foo = "Non-Empty string"
If Not String.IsNullOrEmpty(foo) Then
Console.WriteLine("Foo is not empty.")
End If
End Sub
您的字符串是否有默认值,它们实际上是“”?如果您使用:
If Not Component Is Nothing Then
End If
我以前得到的一件事是空间。当您在“监视”窗口中查看变量时,您无法看到它,但它会使字符串不为空或null。不是这样,而是提示为+1。为了完整起见,只需添加:您对组件为空字符串的假设一定是错误的。它不是一个非空字符串,就是什么也没有。