2017-06-12 74 views
-1

我一直在尝试组合或配对两个文本文件。 一个文件包含用户:密钥 另一个文件包含密钥:通过 我想创建第三个文本文件,其中包含基于密钥匹配的相应的User:Pass对。 这里是我用尽最近两个.txt之间的项目配对

Private Sub Rotate() 
    Dim Cracked() As String = IO.File.ReadAllLines(TextBox1.Text) 
    For Each lineA In Cracked 
     TextBox5.Text = lineA 
    check() 
    Next 
End Sub 
    Private Sub check() 
    Dim toCheck() As String = TextBox5.Text.Split(":") 
    Dim tHash As String = toCheck(0) 
    Dim tPass As String = toCheck(1) 
    Dim lines1() As String = IO.File.ReadAllLines(TextBox2.Text) 
    For Each line In lines1 
     If lines1.Contains(tHash) Then 
      Dim toAdd() As String = line.Split(":") 
      Dim uHash As String = toCheck(0) 
      Dim uUser As String = toCheck(1) 
      ListBox1.Items.Add(uUser + ":" + tPass) 
     End If 
    Next 
End Sub 
    Public Sub CopyListBoxToClipboard(ByVal ListBox2 As ListBox) 

    Dim buffer As New StringBuilder 

    For i As Integer = 0 To ListBox1.Items.Count - 1 
     buffer.Append(ListBox1.Items(i).ToString) 
     buffer.Append(vbCrLf) 
    Next 

    My.Computer.Clipboard.SetText(buffer.ToString) 

End Sub 


Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click 
    CopyListBoxToClipboard(ListBox1) 
    End Sub 

分隔符的变化,但对于现在的作品:。 我试过拆分和匹配,但textbox5不旋转或它通过列表旋转,这就是所有。

+0

你的问题中提到创建第三个文本文件,但无处在你的代码有什么会创建或写入文本文件。请重新说出这个问题,或者包含更多的代码。 – nicko

+0

@nicko固定。简单的复制和粘贴,或者我可以保存到文件路径。 –

回答

1

是这样的吗?

Dim KeyPassFile As String = "..." 
Dim UserKeyFile As String = "..." 
Dim UserPassFile As String = "..." 

Dim KeyPass As New Hashtable 

' Read Key:Pass file 
For Each Line In IO.File.ReadAllLines(KeyPassFile) 
    Dim iStart = Line.IndexOf(":") 
    Dim Key = Line.Substring(0, iStart) 
    Dim Pass = Line.Substring(iStart + 1) 
    KeyPass.Add(Key, Pass) 
Next 

' Create User:Pass file 
Dim OutFile = IO.File.CreateText(UserPassFile) 

' Read User:Key file 
For Each Line In IO.File.ReadAllLines(UserKeyFile) 
    Dim iStart = Line.IndexOf(":") 
    Dim User = Line.Substring(0, iStart) 
    Dim Key = Line.Substring(iStart + 1) 
    If KeyPass.ContainsKey(Key) Then 
     ' We have a match for the key, write it to the file 
     OutFile.WriteLine(User & ":" & KeyPass(Key)) 
    End If 
Next 

OutFile.Close() 

这可能不会对不适合在内存非常大的文件工作,并有在哈希表中插入钥匙没有重复检查,但我会留下点什么给你做.. :)

而且,在你的代码,你看在TextBox2.Text多次有在TextBox1.Text文件中的行指定的文件..

+0

我想知道如果我是:(谢谢你指出这一点。现在试试这个。 –

+0

我试过了“如果不是Keypass.contains(key)那么,IDK什么我做错了 –

+0

我可以看到它背后的逻辑但不能写它在.txt –