"Replace" mit Text aus Datei

  • VB.NET

Es gibt 13 Antworten in diesem Thema. Der letzte Beitrag () ist von Superleo1810.

    "Replace" mit Text aus Datei

    Hallo Leute!
    Ich hänge gerade an einem Projekt, bei dem ich gerne eizelne Zeichen aus einem Text, der in einer Textbox geschrieben steht, mit anderen Zeichen ersetzen möchte, die in einer Textdatei gespeichert sind.

    Hier schonmal ein Ausschnitt aus dem Replace-Prozedere:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. TextToCrypt.Text = texttocrypt.text.Replace("z", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 98)) & _
    2. TextToCrypt.Text = texttocrypt.text.Replace("y", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 97)) & _
    3. TextToCrypt.Text = texttocrypt.text.Replace("x", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 96)) & _
    4. TextToCrypt.Text = texttocrypt.text.Replace("w", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 95)) & _
    5. TextToCrypt.Text = texttocrypt.text.Replace("v", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 94)) & _
    6. TextToCrypt.Text = texttocrypt.text.Replace("u", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 93)) & _
    7. TextToCrypt.Text = texttocrypt.text.Replace("t", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 92)) & _
    8. TextToCrypt.Text = texttocrypt.text.Replace("s", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 91)) & _
    9. TextToCrypt.Text = texttocrypt.text.Replace("r", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 90)) & _
    10. TextToCrypt.Text = texttocrypt.text.Replace("q", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 89)) & _
    11. TextToCrypt.Text = texttocrypt.text.Replace("p", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 88)) & _
    12. TextToCrypt.Text = texttocrypt.text.Replace("o", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 87)) & _
    13. TextToCrypt.Text = texttocrypt.text.Replace("n", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 86)) & _
    14. TextToCrypt.Text = texttocrypt.text.Replace("m", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 85)) & _
    15. TextToCrypt.Text = texttocrypt.text.Replace("l", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 84)) & _
    16. TextToCrypt.Text = texttocrypt.text.Replace("k", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 83)) & _
    17. TextToCrypt.Text = texttocrypt.text.Replace("j", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 82)) & _
    18. TextToCrypt.Text = texttocrypt.text.Replace("i", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 81)) & _
    19. TextToCrypt.Text = texttocrypt.text.Replace("h", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 80)) & _
    20. TextToCrypt.Text = texttocrypt.text.Replace("g", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 79)) & _
    21. TextToCrypt.Text = texttocrypt.text.Replace("f", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 78)) & _
    22. TextToCrypt.Text = texttocrypt.text.Replace("e", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 77)) & _
    23. TextToCrypt.Text = texttocrypt.text.Replace("d", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 76)) & _
    24. TextToCrypt.Text = texttocrypt.text.Replace("c", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 75)) & _
    25. TextToCrypt.Text = texttocrypt.text.Replace("b", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 74)) & _
    26. TextToCrypt.Text = texttocrypt.text.Replace("a", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 73)) & _
    27. TextToCrypt.Text = texttocrypt.text.Replace("0", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 72)) & _
    28. TextToCrypt.Text = texttocrypt.text.Replace("9", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 71)) & _
    29. TextToCrypt.Text = texttocrypt.text.Replace("8", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 70)) & _
    30. TextToCrypt.Text = texttocrypt.text.Replace("7", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 69)) & _
    31. TextToCrypt.Text = texttocrypt.text.Replace("6", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 68)) & _
    32. TextToCrypt.Text = texttocrypt.text.Replace("5", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 67)) & _
    33. TextToCrypt.Text = texttocrypt.text.Replace("4", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 66)) & _
    34. TextToCrypt.Text = texttocrypt.text.Replace("3", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 65)) & _
    35. TextToCrypt.Text = texttocrypt.text.Replace("2", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 64)) & _
    36. TextToCrypt.Text = texttocrypt.text.Replace("1", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 63)) & _
    37. TextToCrypt.Text = texttocrypt.text.Replace("Z", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 62)) & _
    38. TextToCrypt.Text = texttocrypt.text.Replace("Y", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 61)) & _
    39. TextToCrypt.Text = texttocrypt.text.Replace("X", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 60)) & _
    40. TextToCrypt.Text = texttocrypt.text.Replace("W", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 59)) & _
    41. TextToCrypt.Text = texttocrypt.text.Replace("V", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 58)) & _
    42. TextToCrypt.Text = texttocrypt.text.Replace("U", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 57)) & _
    43. TextToCrypt.Text = texttocrypt.text.Replace("T", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 56)) & _
    44. TextToCrypt.Text = texttocrypt.text.Replace("S", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 55)) & _
    45. TextToCrypt.Text = texttocrypt.text.Replace("R", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 54)) & _
    46. TextToCrypt.Text = texttocrypt.text.Replace("Q", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 53)) & _
    47. TextToCrypt.Text = texttocrypt.text.Replace("P", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 52)) & _
    48. TextToCrypt.Text = texttocrypt.text.Replace("O", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 51)) & _
    49. TextToCrypt.Text = texttocrypt.text.Replace("N", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 50)) & _
    50. TextToCrypt.Text = texttocrypt.text.Replace("M", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 49)) & _
    51. TextToCrypt.Text = texttocrypt.text.Replace("L", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 48)) & _
    52. TextToCrypt.Text = texttocrypt.text.Replace("K", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 47)) & _
    53. TextToCrypt.Text = texttocrypt.text.Replace("J", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 46)) & _
    54. TextToCrypt.Text = texttocrypt.text.Replace("I", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 45)) & _
    55. TextToCrypt.Text = texttocrypt.text.Replace("H", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 44)) & _
    56. TextToCrypt.Text = texttocrypt.text.Replace("G", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 43)) & _
    57. TextToCrypt.Text = texttocrypt.text.Replace("F", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 42)) & _
    58. TextToCrypt.Text = texttocrypt.text.Replace("E", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 41)) & _
    59. TextToCrypt.Text = texttocrypt.text.Replace("D", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 40)) & _
    60. TextToCrypt.Text = texttocrypt.text.Replace("C", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 39)) & _
    61. TextToCrypt.Text = texttocrypt.text.Replace("B", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 38)) & _
    62. TextToCrypt.Text = texttocrypt.text.Replace("A", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 37)) & _
    63. TextToCrypt.Text = texttocrypt.text.Replace("|", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 36)) & _
    64. TextToCrypt.Text = texttocrypt.text.Replace("_", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 35)) & _
    65. TextToCrypt.Text = texttocrypt.text.Replace(":", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 34)) & _
    66. TextToCrypt.Text = texttocrypt.text.Replace(";", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 33)) & _
    67. TextToCrypt.Text = texttocrypt.text.Replace("<", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 32)) & _
    68. TextToCrypt.Text = texttocrypt.text.Replace("~", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 31)) & _
    69. TextToCrypt.Text = texttocrypt.text.Replace("¨", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 30)) & _
    70. TextToCrypt.Text = texttocrypt.text.Replace("´", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 29)) & _
    71. TextToCrypt.Text = texttocrypt.text.Replace("\", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 28)) & _
    72. TextToCrypt.Text = texttocrypt.text.Replace("}", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 27)) & _
    73. TextToCrypt.Text = texttocrypt.text.Replace("]", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 26)) & _
    74. TextToCrypt.Text = texttocrypt.text.Replace("[", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 25)) & _
    75. TextToCrypt.Text = texttocrypt.text.Replace("{", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 24)) & _
    76. TextToCrypt.Text = texttocrypt.text.Replace("€", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 23)) & _
    77. TextToCrypt.Text = texttocrypt.text.Replace("$", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 22)) & _
    78. TextToCrypt.Text = texttocrypt.text.Replace("£", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 21)) & _
    79. TextToCrypt.Text = texttocrypt.text.Replace("@", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 20)) & _
    80. TextToCrypt.Text = texttocrypt.text.Replace("§", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 19)) & _
    81. TextToCrypt.Text = texttocrypt.text.Replace("-", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 18)) & _
    82. TextToCrypt.Text = texttocrypt.text.Replace(".", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 17)) & _
    83. TextToCrypt.Text = texttocrypt.text.Replace(",", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 16)) & _
    84. TextToCrypt.Text = texttocrypt.text.Replace(">", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 15)) & _
    85. TextToCrypt.Text = texttocrypt.text.Replace("*", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 14)) & _
    86. TextToCrypt.Text = texttocrypt.text.Replace("^", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 13)) & _
    87. TextToCrypt.Text = texttocrypt.text.Replace("`", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 12)) & _
    88. TextToCrypt.Text = texttocrypt.text.Replace("?", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 11)) & _
    89. TextToCrypt.Text = texttocrypt.text.Replace("=", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 10)) & _
    90. TextToCrypt.Text = texttocrypt.text.Replace(")", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 9)) & _
    91. TextToCrypt.Text = texttocrypt.text.Replace("(", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 8)) & _
    92. TextToCrypt.Text = texttocrypt.text.Replace("/", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 7)) & _
    93. TextToCrypt.Text = texttocrypt.text.Replace("&", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 6)) & _
    94. TextToCrypt.Text = texttocrypt.text.Replace("%", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 5)) & _
    95. TextToCrypt.Text = texttocrypt.text.Replace("¤", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 4)) & _
    96. TextToCrypt.Text = texttocrypt.text.Replace("#", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 3)) & _
    97. TextToCrypt.Text = texttocrypt.text.Replace("!", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 2)) & _
    98. TextToCrypt.Text = texttocrypt.text.Replace("½", ReadLine(Path.GetDirectoryName(Application.ExecutablePath) + "\Text.txt", 1))


    Hier nochmal die ReadLine-Funktion:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Function ReadLine(ByVal filename As String, _
    2. ByVal line As Integer) As String
    3. Try
    4. Dim lines As String() = My.Computer.FileSystem.ReadAllText( _
    5. filename, System.Text.Encoding.Default).Split(vbCrLf)
    6. If line > 0 Then
    7. ' n-te Zeile vom Anfang der Textdatei
    8. Return lines(line - 1)
    9. ElseIf line < 0 Then
    10. ' n-te Zeile beginnend am Ende der Textdatei
    11. Return lines(lines.Length + line - 1)
    12. Else
    13. ' ungültige Zeilennummer
    14. Return ""
    15. End If
    16. Catch ex As Exception
    17. Return ""
    18. End Try
    19. End Function


    Wenn ich jedoch das Programm debugge kommt folgende Fehlermeldung:

    Quellcode

    1. Ungültige Konvertierung von der Zeichenfolge cQ6dzC7N6V#HIf501SsAEZg+54MShRd in Typ Boolean.


    Da ich mich noch als Anfänger in Visual Basic ansehe, bin ich mir nicht sicher, aber bedeutet Boolean nicht eine Aussage wie "true", oder "false"?

    Kann mir bitte jemand erklären, was ich tun soll, damit dies richtig funktioniert?
    Danke im Vorraus!
    Wenn ich mir deinen Code so anschauen, dann würde ich sagen, verwende dafür umbedingt eine For-Schleife. Und deine ReadLine-Funktion ist auch nicht so das Wahre, weil ja bei jedem Aufruf die Datei neu gelesen wird und das Array mit den Zeilen neu erstellt wird. Ich würde das einmal zu Beginn machen und dann bei jedem Schleifendurchgang einfach auf die benötigte Zeile aus Array-Element auslesen.

    Zum eigentlichen Fehler: Mit dem &-Operator bewirkst du, dass die Zeichenketten aneinander gehängt werden und mit dem =-Operator bewirkst du, dass geprüft wird, ob TextToCrypt.Text gleich texttocrypt.text.Replace(...) ist und diese Prüfung gibt einen Wert vom Type Boolean zurück. Ist das überhaupt dein Vorhaben (ich glaube eher, du willst einfach den Text der TextBox durch einen neuen ersetzen)? In welcher Zeile tritt die Exception denn auf (bzw. es wird von Vb wahrscheinlich alles als eine Zeile gehandhabt)?

    Und ja, der eine Variable vom Type Boolean kann entweder den Wert True oder False haben, deswegen klappt es auch nicht die Zeichenfolge in diesen Typ umzuwandeln.
    Pack Dir die Buchstaben in ein Array.
    Lies die Textdatei in ein Array.
    Ersetze in einer Schleife.

    VB.NET-Quellcode

    1. Dim Zeichen() As String = {"z", "y", "x", ...}
    2. Dim Zeilen() As String = System.IO.File.ReadAllLines(Path.GetDirectoryName(Application.ExecutablePath) & "\Text.txt")
    3. Dim text As String = texttocrypt.text
    4. For i As Integer = 0 To Math.Min(Zeichen.Lines, Zeilen.Lines) - 1
    5. text = text.Replace(Zeichen(i), Zeilen(i))
    6. Next
    7. TextToCrypt.Text = text
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Hättest Du eigentlich selbst finden können. :S

    VB.NET-Quellcode

    1. For i As Integer = 0 To Math.Min(zeichen.Length, Zeilen.Length) - 1
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    komisch, funtioniert nicht.
    irgendwie wird der replace-schritt übersprungen.

    hier der bisherige fortschritt:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dim zeichen() As String = {"z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o", "n", "m", "l", "k", "j", "i", "h", "g", "f", "e", "d", "c", "b", "a", "0", "9", "8", "7", "6", "5", "4", "3", "2", "1", "Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A", "|", "_", ":", ";", "<", "~", "¨", "´", "\", "}", "]", "[", "{", "€", "$", "£", "@", "§", "-", ".", ",", ">", "*", "^", "`", "?", "=", ")", "(", "/", "&", "%", "¤", "#", "!", "½"}
    2. Dim Zeilen() As String = File.ReadAllLines(Path.GetDirectoryName(Application.ExecutablePath) & "\text.txt")
    3. Dim rd As New RijndaelManaged
    4. Dim key() As Byte
    5. Dim md5 As New MD5CryptoServiceProvider
    6. If EncryptTextType1.Text = "UTF7" Then
    7. key = md5.ComputeHash(Encoding.UTF7.GetBytes(PasswordToCrypt.Text))
    8. ElseIf EncryptTextType1.Text = "UTF8" Then
    9. key = md5.ComputeHash(Encoding.UTF8.GetBytes(PasswordToCrypt.Text))
    10. ElseIf EncryptTextType1.Text = "UTF32" Then
    11. key = md5.ComputeHash(Encoding.UTF32.GetBytes(PasswordToCrypt.Text))
    12. ElseIf EncryptTextType1.Text = "ASCII" Then
    13. key = md5.ComputeHash(Encoding.ASCII.GetBytes(PasswordToCrypt.Text))
    14. ElseIf EncryptTextType1.Text = "Unicode" Then
    15. key = md5.ComputeHash(Encoding.Unicode.GetBytes(PasswordToCrypt.Text))
    16. ElseIf EncryptTextType1.Text = "BigEndianUnicode" Then
    17. key = md5.ComputeHash(Encoding.BigEndianUnicode.GetBytes(PasswordToCrypt.Text))
    18. ElseIf EncryptTextType1.Text = "Default" Then
    19. key = md5.ComputeHash(Encoding.Default.GetBytes(PasswordToCrypt.Text))
    20. End If
    21. md5.Clear()
    22. rd.Key = key
    23. rd.GenerateIV()
    24. Dim iv() As Byte = rd.IV
    25. Dim ms As New MemoryStream
    26. ms.Write(iv, 0, iv.Length)
    27. Dim cs As New CryptoStream(ms, rd.CreateEncryptor, CryptoStreamMode.Write)
    28. Dim data() As Byte
    29. If EncryptTextType1.Text = "UTF7" Then
    30. data = System.Text.Encoding.UTF7.GetBytes(TextToCrypt.Text)
    31. ElseIf EncryptTextType1.Text = "UTF8" Then
    32. data = System.Text.Encoding.UTF8.GetBytes(TextToCrypt.Text)
    33. ElseIf EncryptTextType1.Text = "UTF32" Then
    34. data = System.Text.Encoding.UTF32.GetBytes(TextToCrypt.Text)
    35. ElseIf EncryptTextType1.Text = "ASCII" Then
    36. data = System.Text.Encoding.ASCII.GetBytes(TextToCrypt.Text)
    37. ElseIf EncryptTextType1.Text = "Unicode" Then
    38. data = System.Text.Encoding.Unicode.GetBytes(TextToCrypt.Text)
    39. ElseIf EncryptTextType1.Text = "BigEndianUnicode" Then
    40. data = System.Text.Encoding.BigEndianUnicode.GetBytes(TextToCrypt.Text)
    41. ElseIf EncryptTextType1.Text = "Default" Then
    42. data = System.Text.Encoding.Default.GetBytes(TextToCrypt.Text)
    43. End If
    44. cs.Write(data, 0, data.Length)
    45. cs.FlushFinalBlock()
    46. Dim encdata() As Byte = ms.ToArray()
    47. TextToCrypt.Text = ""
    48. TextToCrypt.Text = Convert.ToBase64String(encdata)
    49. Dim text As String = TextToCrypt.Text
    50. For i As Integer = 0 To Math.Min(zeichen.Length, Zeilen.Length) - 1
    51. text = text.Replace(zeichen(i), Zeilen(i))
    52. Next
    53. TextToCrypt.Text = text
    54. cs.Close()
    55. rd.Clear()


    verschlüsseln nach Rijndael tut er, jedoch setzt das replace nicht ein.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Superleo1810“ ()

    Superleo1810 schrieb:

    VB.NET-Quellcode

    1. ElseIf EncryptTextType1.Text = "Default" Then
    Mach da einfach ein

    VB.NET-Quellcode

    1. Else
    draus.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    hilft leider auch nichts.

    schließlich wird das

    VB.NET-Quellcode

    1. Dim text As String = TextToCrypt.Text
    2. For i As Integer = 0 To Math.Min(zeichen.Length, Zeilen.Length) - 1
    3. text = text.Replace(zeichen(i), Zeilen(i))
    4. Next
    5. TextToCrypt.Text = text

    ja nicht ausgeführt.
    Bei Dir, bei mir sehrwohl.

    VB.NET-Quellcode

    1. Dim Zeichen() As String = {"z", "y", "x", "w", "a", "b"}
    2. Dim Zeilen() As String = System.IO.File.ReadAllLines("c:\Temp\Text.txt")
    3. Dim text As String = TextBox1.Text.ToArray
    4. For i As Integer = 0 To Math.Min(Zeichen.Length, Zeilen.Length) - 1
    5. text = text.Replace(Zeichen(i), Zeilen(i))
    6. Next
    7. TextBox2.Text = text
    Was steht denn in Deiner Text-Datei drin?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    :D :D :D LOL :D :D :D
    Du ersetzt "z" durch "z", "y" durch "y" "x" durch "x" usw.
    Mach mal

    VB.NET-Quellcode

    1. Dim Zeichen() As String = {"y", "x", "w", ..., "z"}
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!