0
A
回答
0
我已經找到自己的答案,感謝所有誰作爲貢獻
Function FilterArray(ByVal Source As String, ByVal Search As String, Optional _
ByVal Keep As Boolean = True) As String
Dim i As Long
Dim SearchArray() As String
Dim iSearchLower As Long
Dim iSearchUpper As Long
If LenB(Source) <> 0 And LenB(Search) <> 0 Then
SearchArray = Split(Search, " ")
Else
FilterArray = Source
Exit Function
End If
iSearchLower = LBound(SearchArray)
iSearchUpper = UBound(SearchArray)
For i = iSearchLower To iSearchUpper
DoEvents
Source = Join(Filter(Split(Source, " "), SearchArray(i), Keep, _
vbTextCompare), " ")
Next i
FilterArray = Source
End Function
0
數組B中的所有元件。在這種情況下,I」的陣列d只是對一個數組進行排序,然後遍歷第二個數組,如果發現它們,則從第一個數組中刪除它們。這個算法似乎需要O(n lg n)並且做你想做的事情。
0
假設他們爲整型數組:
Dim FilteredArray() As Integer
Dim X as Long
Dim Y as Long
Dim Z as Long
Dim bDupe as Boolean
Z = -1
For X = 0 to UBound(A)
bDupe = False
For Y = 0 to UBound(B)
If A(X) = B(Y) Then
bDupe = True
Exit For
End If
Next
If Not bDupe Then
Z = Z + 1
ReDim Preserve FilteredArray(Z)
FilteredArray(Z) = A(X)
End If
Next
+0
數組elemenets是字符串 – Smith 2011-02-04 08:15:22
0
嘗試是這樣的
Option Explicit
Private Sub Form_Load()
Dim vElem As Variant
For Each vElem In SubstractArray(Array("aa", "b", "test"), Array("c", "aa", "test"))
Debug.Print vElem
Next
End Sub
Private Function SubstractArray(arrSrc As Variant, arrBy As Variant) As Variant
Dim cIndex As Collection
Dim vElem As Variant
Dim vRetVal As Variant
Dim lIdx As Long
If UBound(arrSrc) < LBound(arrSrc) Then
Exit Function
End If
'--- build index collection
Set cIndex = New Collection
For Each vElem In arrBy
cIndex.Add vElem, "#" & vElem
Next
'--- allocate output array
lIdx = LBound(arrSrc)
ReDim vRetVal(lIdx To UBound(arrSrc)) As Variant
'--- iterate source and seek in index
For Each vElem In arrSrc
On Error Resume Next
IsObject cIndex("#" & vElem)
If Err.Number <> 0 Then
vRetVal(lIdx) = vElem
lIdx = lIdx + 1
End If
On Error GoTo 0
Next
'--- shrink output array
If lIdx = LBound(vRetVal) Then
vRetVal = Split(vbNullString)
Else
ReDim Preserve vRetVal(0 To lIdx - 1) As Variant
End If
SubstractArray = vRetVal
End Function
相關問題
- 1. VB.Net濾波器陣列等效於VB6
- 2. 濾波器陣列
- 3. 濾波器陣列
- 4. 濾波器陣列
- 5. 另一個陣列的AngularJS濾波器陣列
- 6. PHP濾波器陣列由另一真/假陣列
- 7. 濾波器陣列子陣
- 8. 濾波器陣列到另一個陣列使用更新的值
- 9. 過濾器使用另一個陣列
- 10. 濾波陣列
- 11. 濾波陣列
- 12. 濾波器陣列 - SWIFT
- 13. 濾波器陣列/反應
- 14. 濾波器在C#陣列
- 15. JavaScript的濾波器陣列
- 16. 陣列的角度濾波器陣列
- 17. 陣列內的濾波器陣列
- 18. AngularJS陣列濾波根據另一個陣列
- 19. 從濾波陣列
- 20. 濾波陣列段
- 21. NSPredicate濾波器陣列,用於NSDate的
- 22. Angular2-來自另一個陣列的對象的濾波器陣列
- 23. 使用vb6將陣列數據複製到另一個陣列
- 24. 濾波器使用的數據的陣列中的一個UITableView
- 25. 採樣使用另一種陣列
- 26. 濾波器陣列對特定參數
- 27. 如何寫濾波器檢查陣列
- 28. 掩蔽陣列的中值濾波器
- 29. MATLAB多維濾波器陣列
- 30. 濾波器陣列的關鍵
,給予兩個數組「A」和「B」從`A`獲取元素數組,這個元素也存在於`B`中? – 2011-02-03 18:59:26
沒有我添加更多信息 – Smith 2011-02-03 19:19:23