【发布时间】:2016-12-05 13:55:27
【问题描述】:
我查看了List.Contains returns false, even though it seems it should return true,但他的代码结构与我的有点不同,所以我不确定我是否有同样的问题。
在我继续之前,让我解释一下我的结果应该是什么。
我们有 2 个输入文件,文件 1 带有 email:hash,另一个带有 email:hash 和 email:plain 的混合。
结束输出:如果第二个文件在 : 之后有明文,则输出它(确保在输出文件 1 的电子邮件时不重复:如果没有为该电子邮件/哈希生成文件 2 行,则确保不重复),否则输出哈希.
tl;dr - 基本上将第二个文件 overwrite prioritized 放在第一个文件之上。
(First File Randomized)
ABC_123@gmail.com:f6deea50e7eeb2d930fab83ccc32cdfe
123abc@domain.ext:82e6eeea4060c90cc3dc6ddd25885806
123_ABC@gmail.com:8fa5104d4d995dc153e5509ab988bcfd
abc123@email.com:2d366131008f89781b8379bed3451656
(Second File Randomized)
123abc@domain.ext:aaaaaaaa
ABC_123@gmail.com:cccccccc
abc123@email.com:bbbbbbbb
newemail@hotmail.com:ddddddddd
Output should be:
123_ABC@gmail.com:8fa5104d4d995dc153e5509ab988bcfd
123abc@domain.ext:aaaaaaaa
ABC_123@gmail.com:cccccccc
abc123@email.com:bbbbbbbb
newemail@hotmail.com:ddddddddd
(Output from Tests - "->" lines shouldn't be outputted.)
123_ABC@gmail.com:8fa5104d4d995dc153e5509ab988bcfd
->123abc@domain.ext:82e6eeea4060c90cc3dc6ddd25885806
123abc@domain.ext:aaaaaaaa
ABC_123@gmail.com:cccccccc
->ABC_123@gmail.com:f6deea50e7eeb2d930fab83ccc32cdfe
abc123@email.com:bbbbbbbb
newemail@hotmail.com:ddddddddd
在第二个 OpenFileDialog 块中,它始终返回 false,直到 For Each combo as Match in matches 中的最后一行。
奇怪的是,如果我将第二个正则表达式从 (.*)@(.*):(.*) 更改为 (.*)@(.*):([a-f0-9]{32}) 出于某种原因它会起作用,问题是它只会匹配 Email@domain.ext:{md5} 而不会匹配例如 Email@domain.ext:abc123 这是一个要求。(最新的代码更新,我一直在搞乱尝试修复它,它更破坏了它,所以现在这甚至不起作用)。
我睡了一次然后回来尝试修复它,到目前为止我几乎在那里,它正在正确覆盖,除了一封电子邮件:出于某种原因哈希。
Image showing error 如您所见,它将 123abc@domain.ext 从哈希更改为 aaaaaaa,但对于 ABC_123@gmail.com,它并没有出于某种奇怪的原因。同样是的,abc123@email.com 哈希确实发生了变化,所以奇怪的是随机 email:hash 没有改变。
我已经连续 12 多个小时在此工作了大约 9。 (毫不夸张),我真的很想了解正在发生的事情。
我已经尝试了很多替代方法,以至于我现在都记不起来了。
代码:(更新 x3)
提醒:阅读上面关于我试图实现的目标:)
#Region "Merge Combo's"
Private Sub List_Merge_Click(sender As Object, e As EventArgs) Handles List_Merge.Click
Dim ofd = New OpenFileDialog()
ofd.Title = "Import..."
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
ofd.Filter = "Text files|*.txt"
ofd.Multiselect = True
'If the user selects 2 Files;
If (ofd.ShowDialog() = DialogResult.OK And ofd.CheckFileExists = True) Then
'Make sure there are no previously stored Conversions;
ActionList2.Items.Clear()
'Variables;
Dim MergedCombos As Integer = 0
Dim TotalCombos As Integer = 0
Try
For Each filename As String In ofd.FileNames
Using sr As New StreamReader(filename)
Dim result = filename.Union(filename, New MailEqualityComparer)
'Get all Matches found from the Regex Condition;
Dim combos As MatchCollection = New Regex("^([^@]+)@(.*):(.*)$", RegexOptions.Multiline).Matches(sr.ReadToEnd)
'Add each Match to the ActionList except for Duplicates;
For Each combo As Match In combos
'Increment the Total Combo's count;
TotalCombos += 1
'If the ActionList doesn't contain the same Combo;
If Not ActionList2.Items.Contains(combo.Value) Then
'If the email is already in the ActionList;
If IsInListbox(ActionList2, combo.Groups(1).Value + "@" + combo.Groups(2).Value) = True Then
'This combo is presumed to be a Hash Decrypted Combo - Overwrite it with the Encrypted Hash;
ActionList2.Items.Add(combo.Value)
'Remove the Hash Item from ActionList;
ActionList2.Items.RemoveAt(FindListboxIndex(ActionList2, combo.Groups(1).Value + "@" + combo.Groups(2).Value))
Else
'Add the Combo;
ActionList2.Items.Add(combo.Value)
End If
End If
Next
End Using
Next
Catch ex As Exception
Console.WriteLine("Error: " + ex.ToString)
Finally
'If atleast 1 Item is in the ActionList, Enable the Export Button;
If ActionList2.Items.Count > 0 Then
ExportButton.Enabled = True
ExportButton.BackColor = Color.FromArgb(149, 255, 141)
End If
'Update the Merged Combo's count;
StatusBar_LeftText.Text = MergedCombos.ToString
'If MergedCombos are less than TotalCombos, Add a "x Duplicates Removed" message;
If MergedCombos < TotalCombos Then
StatusBar_LeftText.Text += " - " + (TotalCombos - MergedCombos).ToString + " Duplicates Removed"
End If
'Autoscroll;
ActionList2.TopIndex = ActionList2.Items.Count - 1
End Try
End If
End Sub
Private Function FindListboxIndex(lb As ListBox, searchString As String) As Integer
For i As Integer = 0 To lb.Items.Count - 1
If lb.Items(i).ToString().Contains(searchString) Then
Return i
Exit Function
End If
Next
Return -1
End Function
Private Function IsInListbox(lb As ListBox, searchString As String) As Boolean
For i As Integer = 0 To lb.Items.Count - 1
If lb.Items(i).ToString().Contains(searchString) Then
Return True
Exit Function
End If
Next
Return False
End Function
#End Region
【问题讨论】:
-
没人评论吗?有什么你们认为我应该尝试的吗?测试?等等?没有? o.o
-
如果你们找不到帮助的方法 - 请为我的问题投票,因为这就是它的目的,投票将帮助其他人找到我的问题 = 更多答案/建议的可能性!谢谢
-
仍然需要答案 - 上面的代码应该可以工作,但由于某种原因它并不总是有效。
标签: vb.net visual-studio visual-studio-2015