Filtern

  • VB.NET

Es gibt 39 Antworten in diesem Thema. Der letzte Beitrag () ist von Lupus.

    Thx, das funktioniert schonmal super, nur wie mache ich es, wenn "b" z.B "1" sein soll?
    Muss ich dann:

    VB.NET-Quellcode

    1. TextBox1.Text = TextBox1.Text.Replace("a", "0")
    2. TextBox1.Text = TextBox1.Text.Replace("b", "1")

    Oder gibts da ne einfacherer Methode?
    wie stellst du dir denn "einfacher" vor? noch kürzer oder was?

    wenn das jetzt so weiter geht und du c zu 2 und d zu 3 usw haben willst kannst du das mit einer schleife lösen.


    /edit:
    @lupus: lol, stimmt; der code ist ziemlich ähnlich :D

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Phil“ ()

    Mh, okay, werds mal selber mit ner Schleife versuchen, glaub ich wüsste wie.

    Ne ich dachte halt es gibt sowas wie

    VB.NET-Quellcode

    1. TextBox1.Text = TextBox1.Text.Replace("a", "0" & "b", "1")

    Oder so ^^

    Aber Thx an euch beide, habt mir weiter geholfen =)


    lg

    Chris
    :D
    also:

    VB.NET-Quellcode

    1. Dim BArray(99, 1) As String
    2. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3. BArray(1, 0) = "a"
    4. BArray(1, 1) = "0"
    5. BArray(2, 0) = "b"
    6. BArray(2, 1) = "1"
    7. '...
    8. End Sub
    9. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    10. For a As Single = 1 To 99
    11. If BArray(a, 0) = "" Then Exit For
    12. TextBox1.Text = TextBox1.Text.Replace(BArray(a, 0), BArray(a, 1))
    13. Next
    14. End Sub
    Hey, coole Idee ;)
    Werd mal gucken was von beiden ich benutzen werd =)

    e:/ So nächstens Problem.
    Bin jetzt soweit:

    VB.NET-Quellcode

    1. TextBox2.Text = TextBox1.Text.Replace("a", "001")
    2. TextBox2.Text = TextBox1.Text.Replace("b", "002")
    3. TextBox2.Text = TextBox1.Text.Replace("c", "003")
    4. [...]

    Also ich werd mal deutlicher....es soll ne kleine Geheimschrift werden ^^.
    Nur wenn ich das jetzt wieder entcoden möchte, soll er splitten bei alles 3 Ziffen.
    Sprich:
    001002001002
    wäre ja "abab".
    Nur er soll hier splitten:
    001|002|001|002
    Nur hab ich erlich gesagt noch nie mit der Split Funktion gearbeitet.
    Also, was mach ich da nun?

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Metal Freak“ ()

    wie wärs denn damit:

    VB.NET-Quellcode

    1. Dim Text As String = ""
    2. For Each a As String In TextBox1.Text.Split("|") ' teilt den Text bei jedem "|" auf
    3. Select Case a
    4. Case "001"
    5. Text += "a"
    6. Case "002"
    7. '...
    8. End Select
    9. 'oder, wenn du Arrays benutzt gehts schneller:
    10. For b As Single = 1 To 99
    11. If BArray(b, 0) = "" Then Exit For
    12. If BArray(b, 1) = a Then Text += BArray(b, 1) : Exit For
    13. Next
    14. Next
    Mh..erlich gesagt verstehe ich dein Code nicht..
    also ich habs mal so versucht:

    VB.NET-Quellcode

    1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    2. TextBox2.Text = TextBox1.Text.Replace("a", "001")
    3. TextBox2.Text = TextBox1.Text.Replace("b", "002")
    4. TextBox2.Text = TextBox1.Text.Replace("c", "003")
    5. TextBox2.Text = TextBox1.Text.Replace("d", "004")
    6. TextBox2.Text = TextBox1.Text.Replace("e", "005")
    7. TextBox2.Text = TextBox1.Text.Replace("f", "006")
    8. TextBox2.Text = TextBox1.Text.Replace("g", "007")
    9. TextBox2.Text = TextBox1.Text.Replace("h", "008")
    10. TextBox2.Text = TextBox1.Text.Replace("i", "009")
    11. TextBox2.Text = TextBox1.Text.Replace("j", "010")
    12. TextBox2.Text = TextBox1.Text.Replace("k", "011")
    13. TextBox2.Text = TextBox1.Text.Replace("l", "012")
    14. TextBox2.Text = TextBox1.Text.Replace("m", "013")
    15. TextBox2.Text = TextBox1.Text.Replace("n", "014")
    16. TextBox2.Text = TextBox1.Text.Replace("o", "015")
    17. End Sub

    VB.NET-Quellcode

    1. Private Sub EntschluesselButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2. TextBox3.Text = TextBox2.Text.Replace("001", "a")
    3. TextBox3.Text = TextBox2.Text.Replace("002", "b")
    4. TextBox3.Text = TextBox2.Text.Replace("003", "c")
    5. TextBox3.Text = TextBox2.Text.Replace("004", "d")
    6. TextBox3.Text = TextBox2.Text.Replace("005", "e")
    7. TextBox3.Text = TextBox2.Text.Replace("006", "f")
    8. TextBox3.Text = TextBox2.Text.Replace("007", "g")
    9. TextBox3.Text = TextBox2.Text.Replace("008", "h")
    10. TextBox3.Text = TextBox2.Text.Replace("009", "i")
    11. TextBox3.Text = TextBox2.Text.Replace("010", "j")
    12. TextBox3.Text = TextBox2.Text.Replace("011", "k")
    13. TextBox3.Text = TextBox2.Text.Replace("012", "l")
    14. TextBox3.Text = TextBox2.Text.Replace("013", "m")
    15. TextBox3.Text = TextBox2.Text.Replace("014", "n")
    16. TextBox3.Text = TextBox2.Text.Replace("015", "o")
    17. End Sub


    Klappt aber i-wie nicht ^^
    das problem ist, wenn du die Zahlen nicht irgendie voneinander trennst (bei mir wars eben mit "|"), kanst du nicht unterscheiden, ob "010011" jetzt "01" + "001" + "1" oder "010" + "011" heißt.
    Zu meinem Code:
    Bei der Split-Anweisung wird ein Array erstellt (das "|" fällt automatisch weg), der dann mit dem for each abgefragt wird. Dann wird kontrolliert was für die Zeichenfolge eingesetzt werden soll (mit Select case, oder bei Arrays, indem im Array die passende Zeichenfolge gesucht wird.). Deshalb würd ich an deiner Stelle Arrays nemen, weil du alles dann nur einmal schreiben musst.

    VB.NET-Quellcode

    1. Dim Text As String = ""
    2. For Each a As String In TextBox1.Text.Split("|") ' teilt den Text bei jedem "|" auf
    3. Select Case a
    4. Case "001"
    5. Text += "a"
    6. Case "002"
    7. '...
    8. End Select
    9. 'oder, wenn du Arrays benutzt gehts schneller:
    10. For b As Single = 1 To 99
    11. If BArray(b, 0) = "" Then Exit For
    12. If BArray(b, 1) = a Then Text += BArray(b, 1) : Exit For
    13. Next
    14. Next

    Aber wie sollen die "|" da rein kommen? ^^.
    Dann muss ich ja beim BArray beim Form_Load überall n' "|" hinter die Nummer schreiben..oder?...eigentlich will ich nicht dass das mit | gemacht wird...sondern dass er automatisch bei jeder 5 stelle splittet...
    ach so, dann versuch mal das (habs selbst nicht getestet...):

    VB.NET-Quellcode

    1. Dim Text As String = "", Textarray(999) As String
    2. For a As Single = 0 To TextBox1.Text.Length
    3. Textarray(999) = TextBox1.Text.Substring(a, 3) 'oder, wenn die Teile jeweils 5 Zeichen hat, statt 3 5
    4. Next
    5. For Each a As String In Textarray
    6. If a = "" Then Exit For
    7. Select Case a
    8. ' usw.
    Das verstehe ich jetz garnicht mehr :D
    Hat das jetzt noch was mit BArray zu tun?
    Eben hab ich das ja noch gecheckt mit
    BArray(1, 0) = "a"
    BArray(1, 1) = "001"
    und
    For a As Single = 1 To 99
    If BArray(a, 0) = "" Then Exit For
    TextBox2.Text = TextBox1.Text.Replace(BArray(a, 0), BArray(a, 1))
    Next
    aber jetzt bin ich ziemlich verwirrt, sry :(
    also, ich schreib mal den ganzen code, hab selbst nen paar fehler gemacht, aber so sollte es klappen:

    VB.NET-Quellcode

    1. Dim BArray(99, 1) As String
    2. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3. BArray(1, 0) = "a"
    4. BArray(1, 1) = "000"
    5. BArray(2, 0) = "b"
    6. BArray(2, 1) = "001"
    7. '...
    8. End Sub
    9. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    10. ' in Zahlen umwandeln:
    11. For a As Single = 1 To 99
    12. If BArray(a, 0) = "" Then Exit For
    13. TextBox1.Text = TextBox1.Text.Replace(BArray(a, 0), BArray(a, 1))
    14. Next
    15. End Sub
    16. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    17. 'wieder zurückumwandeln:
    18. Dim Text As String = "", Textarray(999) As String, c As Single = 0 'Text ist der neue Text
    19. For a As Single = 0 To TextBox1.Text.Length - 3 Step 3
    20. Textarray(c) = TextBox1.Text.Substring(a, 3) 'Code wird aufgeteilt (hab hier c vergessen, sorry)
    21. c += 1
    22. Next
    23. For Each a As String In Textarray ' jeder Teil wird geprüft und der entsprechende Buchstaben eingesetzt
    24. If a = "" Then Exit For
    25. For b As Single = 1 To 99
    26. If BArray(b, 0) = "" Then Exit For
    27. If BArray(b, 1) = a Then Text += BArray(b, 0) : Exit For ' sorry hab mich vorhin verschrieben :(
    28. Next
    29. Next
    30. TextBox1.Text = Text
    31. End Sub
    noch was, wie du die die sache mit dem Eintragen sparen kannst:

    VB.NET-Quellcode

    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2. For a As Single = 0 To 25
    3. BArray(a, 0) = Chr(a + 65) 'chr(65) ist "A"
    4. BArray(a, 0) = a.ToString
    5. Do Until BArray(a, 0).Length = 3
    6. BArray(a, 0) = "0" + BArray(a, 0)
    7. Loop
    8. Next
    9. End Sub

    und wenn du Groß- und Kleinschreibung beachten willst, musst du halt noch die kleinen Buchstaben eintragen (ab chr(97))