比较两个文本文件中的数据
比如说两个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
。。。下面还有好多行
两个文本中数据一样的行在另外一个文本中原样输出,不一样的不用管。
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