Dim arr As Variant: arr = Array("hello", "stupid", "world")
Dim newArr As Variant: newArr = Filter(arr, "stupid", False)
Debug.Print Join(newArr, " ")
Filter的VB.Net等价物是什么?任何帮助将不胜感激!编辑:(我正在寻找2.0 .NET Framework解决方案)
答案 0 :(得分:2)
或许这样的事情(假设VB 10):
Dim arr As String() = {"hello", "stupid", "world"}
Dim filteredArray = (from s in arr
Where s <> "stupid"
Select s).ToArray()
另一种方法是使用Except(可在.Net 3.5中使用):
Dim words As String() = {"hello", "stupid", "world"}
Dim excludedWords As String() = {"stupid"}
Dim filteredArray = words.Except(excludedWords).ToArray()
答案 1 :(得分:0)
对于.NET 2.0,您可以使用Array.FindAll方法,如下所示:
Dim arr As String() = New String() {"hello", "stupid", "world"}
Dim newArr As String() = Array.FindAll(arr, AddressOf RemoveElements)
使用此谓词:
Private Shared Function RemoveElements(ByVal s As String) As Boolean
Return Not s.Equals("stupid")
End Function