2017-06-12 71 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 –