我必须列出许多变体。第一个列表样本
清单 1)
hkdhksa
OP-ID:111112
jklfjdlkfsd
hfldhfjksdf
OP-ID:111113
ghjg
OP-ID:111114
OP-ID:111115
gjgjhghgjhg
OP-ID:111116
OP-ID:111117
OP-ID:111118
清单 2)
操作 ID:111112
操作 ID:11113
操作 ID:111114
操作 ID:111115
操作 ID:111117
结果将是: OP-ID: 11118 不在列表 2 中
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 HashSet(Of String) '!
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(",")
If line = ("OP-ID: ") Like "OP-ID:*" Then
If Not file1.ContainsKey(part(0)) Then file1.Add(part(0), line)
End If
Next
For Each line As String In System.IO.File.ReadAllLines(TEST2)
Dim part() As String = line.Split(",")
If Not file2.ContainsKey(part(0)) Then file2.Add(part(0), line) '!
Next
Dim keysInList1ThatAreNotInList2 = file1.Keys.Except(file2.Keys)
Dim values = From key In keysInList1ThatAreNotInList2 Select file1(key)
Dim str = String.Join(vbCrLf, values)
txtResults.Text = ("IDs should not be in list: " & str)
End Sub