vb 把list2中没出现过的字符从list1中剔除

2024-12-12 08:43:58
推荐回答(3个)
回答1:

Dim i, j, k As Integer
Dim State As Integer
Dim A()
k = 0
For i = 0 To List1.ListCount - 1
State = 0
For j = 0 To List2.ListCount - 1
If List1.List(i) = List2.List(j) Then
State = 1
End If
Next
If State = 1 Then
ReDim Preserve A(k)
A(k) = List1.List(i)
k = k + 1
End If
Next
List1.Clear
For k = 0 To UBound(A)
List1.AddItem A(k), k
Next
试试吧,应该可以,我随意弄了几组数试了一下

回答2:

挨个比较。

回答3:

for i = 0 to list2.listcount -1
for j = i to list2.listcount -1
if list2.list(i)=list2.list(j) then
list1.additem list2.list(i)
i = i+1
end if
next j
next i