注册 登录
编程论坛 VB6论坛

比较两个文本文件中的数据

liu753159 发布于 2023-01-29 14:01, 1075 次点击
比如说两个TXT文件
a.txt和b.txt
a.txt数据为
1 2 4 8 9
3 5 7 8 9
2 4 5 7 10
。。。下面还有好多行

b.txt数据为
1 2 4 8 9
1 2 5 8 9
2 4 5 7 10
。。。下面还有好多行

两个文本中数据一样的行在另外一个文本中原样输出,不一样的不用管。
4 回复
#2
mrexcel2023-01-29 21:50
将a.txt的行读出存到字典,将b.txt的行读出逐行判断是否在字典之中
#3
liu7531592023-01-30 21:45
没高手给指点下啊
#4
mrexcel2023-01-31 14:18
程序代码:
Sub test()
Dim txt As String, s() As String
Open "a.txt" For Input As #1
txt = vbCrLf & StrConv(InputB(LOF(1), 1), vbUnicode) & vbCrLf
Close #1
Open "b.txt" For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
For i = 0 To UBound(s)
If InStr(txt, vbCrLf & s(i) & vbCrLf) = 0 Then s(i) = "@"
Next
Open "c.txt" For Output As #1
Print #1, Join(Filter(s, "@", False), vbCrLf)
Close #1
End Sub
#5
liu7531592023-01-31 23:06
回复 4楼 mrexcel
非常感谢!!!!!!虽然没看太懂,但是可行。
1