vb6 - VB6比较list1和list2并从list2中删除不需要的项目
问题描述
我正在尝试比较 vb6 中的 2 个列表框,list2 项目应该匹配 list1 中的项目,然后从 list2 中删除不匹配的字符串。
清单 1 项:
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
清单 2 项:
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
按钮代码:
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 应该有相同的项目删除其他不匹配的垃圾字符串。
解决方案
使用字符串和 InStrB() 函数:
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
推荐阅读
- .net - 在编写正则表达式方面需要帮助
- python - Pyspark sparkSession 在 pycharm 中运行时关闭后抛出连续的异常日志流
- safari - Safari 不透明动画有时会失败
- winapi - CreateCompatibleBitmap 产生黑色单色(即使使用屏幕直流)
- slack - 使用 Bolt for java 的动态块和块动作
- python - 如何基于 StandardScaler 构建自定义缩放器?
- firebase - 如何防止拥有我的 google-services.json 的人访问我的项目?
- r - 将几何点ggplot的星号与位置闪避对齐
- java - 通过 JCo 以事务方式调用 BAPI RFC
- flutter - 具有恢复的活动/非活动轨道样式的滑块