vb实现查找txt重复内容
查找A.txt中的重复内容,如果有相同则清除B.txt中的内容
Public A临时库 As String Public B临时库 As String Private Sub Command1_Click() Dim A数据, B数据 List1.Clear A临时库 = "": B临时库 = "" '------------------------------↓处理数据 Open "C:\A.txt" For Input As #1 Do While Not EOF(1) DoEvents Line Input #1, A数据 If A数据 = "" Then Else If InStr(A临时库, A数据) > 0 Then List1.AddItem A数据 Else A临时库 = A临时库 & A数据 & IIf(EOF(1), "", vbCrLf) End If End If Loop Close #1 '------------------------------↑处理数据 On Error Resume Next Open "C:\A.txt" For Output As #1 Print #1, A临时库 Close #1 '------------------------------↓处理数据 Open "C:\B.txt" For Input As #1 Do While Not EOF(1) DoEvents Line Input #1, B数据 If B数据 = "" Then Else ' For i = 0 To List1.ListCount - 1 If List1.List(i) = B数据 Then Exit For Next If List1.List(i) = B数据 Then Else B临时库 = B临时库 & B数据 & IIf(EOF(1), "", vbCrLf) End If ' End If Loop Close #1 '------------------------------↑处理数据 On Error Resume Next Open "C:\B.txt" For Output As #1 Print #1, B临时库 Close #1 '------------------------------ End Sub
On Error Resume Next Open "C:\A.txt" For Output As #1 Print #1, A临时库 Close #1