首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VB6比较list1和list2并从list2中删除不需要的项

VB6比较list1和list2并从list2中删除不需要的项
EN

Stack Overflow用户
提问于 2019-09-10 07:34:10
回答 1查看 65关注 0票数 1

我正在尝试比较vb6中的2个列表框,list2项应该匹配list1中的项,然后从list2中删除不匹配的字符串。

list1项目:

代码语言:javascript
复制
ls-05
ls-06
ls-12
mg_01.rom
mg_02.rom
mg_05.rom
mg_06.rom
mg_m07.rom
mg_m08.rom
mg_m09.rom
mg_m10.rom
mg_m11.rom
mg_m12.rom
mg_m13.rom
mg_m14.rom

list2项目:

代码语言:javascript
复制
ls-05
ls-05.12e
ls-06
ls-06.10e
ls-11
ls-11.2l
ls-12
ls-12.7l
mg_01.rom
mg_02.rom
mg_05.rom
mg_06.rom
mg_m07.rom
mg_m07.rom2
mg_m08.rom
mg_m08.rom3
mg_m09.rom
mg_m09.rom2
mg_m10.rom
mg_m10.rom3
mg_m11.rom
mg_m11.rom0
mg_m12.rom
mg_m12.rom1
mg_m13.rom
mg_m13.rom0
mg_m14.rom
mg_m14.rom1

按钮代码:

代码语言:javascript
复制
For ii = List1.ListCount - 1 To 0 Step -1
    For i = List1.ListCount - 1 To 0 Step -1
        If List1.List(i) = List2.List(ii) Then Exit For ' no need to keep looping, its a match. i will be > -1
    Next
    If i = -1 Then ' all items in list1 were searched, but no matches found, so remove it
        List2.RemoveItem ii
    End If
Next

所以我想要的最终结果是list2应该有相同的项目,删除其他不匹配的垃圾字符串。

EN

回答 1

Stack Overflow用户

发布于 2019-09-18 04:52:38

使用字符串和InStrB()函数:

代码语言:javascript
复制
dim lstitm as string, str2 as string, count as integer

count = list2.listcount

for i = 0 to count - 1
  str2 = str2 & list2.list(i) & ";"
next i

list2.clear

count = list1.listcount

for i = 0 to count -1
 lstitm = list1.list(i)
 if instrb(1,str2,lstitm) <> 0 then list2.additem lstitm
next i
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57862316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档