Public Class Form1
Const TEST1 = "\\folder\compare\list1.txt"
Const TEST2 = "\\folder\compare\list2.txt"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare two dictionaries. The key for each will be the text from the input line up to,
'but not including the first ",". The valus for each will be the entire input line.
Dim file1 As New Dictionary(Of String, String)
Dim file2 As New Dictionary(Of String, String)
For Each line As String In System.IO.File.ReadAllLines(TEST1)
Dim part() As String = line.Split(",")
file1.Add(part(0), line)
Next
For Each line As String In System.IO.File.ReadAllLines(TEST2)
Dim part() As String = line.Split(",")
file2.Add(part(0), line)
Next
AddText("The following lines from " & TEST2 & " are also in " & TEST1)
For Each key As String In file2.Keys
If file1.ContainsKey(key) Then
AddText(file2(key))
End If
Next
End Sub
Private Sub AddText(ByVal text As String)
txtResults.Text &= text & vbCrLf
End Sub
列表 1)12345
列表 2)1234
结果:5 不在列表 1 中
我想比较 vb.net 中的两个文本文件以检查是否有不在列表一中的值 我面临的问题是列表比较所有匹配的值,但我还想要一个不匹配的值列表。我想显示列表 1 中不在列表 2 中的值。