Hilfe beim splitten von Strings. Hilfe beim splitten von Strings.
Ergebnis 1 bis 7 von 7
  1. 11.09.2012, 17:46
    #1
    Hallo Community, ich bitte euch noch ein mal um Hilfe. Ich versuche mich an C# for Windows Phone und versuche gerade einen Text zu splitten. Also z.B. die Eingabe eines Users: "Hallo + Wie + Geht + Es + Dir" in "Hallo wie geht es dir".
    Code:
    [FONT=Consolas][FONT=Consolas][FONT=Consolas]private[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]void[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas] Button_Click_1([/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]object[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas] sender, [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]RoutedEventArgs[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas] e)[/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas]
             {
    
    [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]string[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas] userEingabe;[/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas]
    
                 userEingabe = myTextBox1.Text;
    
    
    [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]char[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas][] delimiterChars = { [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]' '[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas],[/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]'+'[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas]};[/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas]
               
    
    
    [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]string[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas] text = userEingabe;[/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas]
    [/FONT][/FONT][FONT=Consolas][FONT=Consolas]            myTextBlock1.Text = text;                           [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]//ausgabe des Originaltextes[/FONT][/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas][FONT=Consolas]
    [/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas]
    [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]string[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas][] words = text.Split(delimiterChars);[/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas]
    [/FONT][/FONT][FONT=Consolas][FONT=Consolas]            myTextBlock2.Text = words.Length.ToString();        [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]//ausgabe der anzahl der Wörter[/FONT][/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas][FONT=Consolas]
    [/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas]
                
    
    [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]foreach[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas] ([/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]string[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas] s [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]in[/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas] words)[/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas]
                 {
    
    [/FONT][/FONT][FONT=Consolas][FONT=Consolas]                myTextBlock3.Text = s;                          [/FONT][/FONT][FONT=Consolas][FONT=Consolas][FONT=Consolas]// alle einzelnen wörter??????[/FONT][/FONT][/FONT]
    [FONT=Consolas][FONT=Consolas][FONT=Consolas]
    [/FONT][/FONT][/FONT][FONT=Consolas][FONT=Consolas]            }
    [/FONT][/FONT]
    vielleicht hilft euch das weiter bei meinem Problem. Wie kann ich jetzt nur die Worte wieder ausgeben? Eventuell auch Zahlen davon trennen? Und wenn wir so weit kommen, die Wörter in Strings Speichern und Die Zahlen weiter nutzen in Ints? Wäre super wenn ihr mir dabei behilflich sein könnt ich hoffe ihr versteht mein Problem. danke im Vorraus Agredo
    0
     

  2. du hast die Wörte in einen array gespeichert. also musst du diesen wieder zusammenfügen.
    Code:
    string strFiller;
    foreach (string s in words)
    
                 {
    
                    strFiller += s;                          // fügt jedes mal s zu strFiller hinzu.
                    strFiller = strFiller+s;                // geht genau so, ist nur nicht so hübsch ;) 
    
                }
    myTextBlock3.Text = strFiller;                     //und nun ausgeben
    0
     

  3. 11.09.2012, 18:18
    #3
    danke dür die schnelle Antwort aber er gibt mir dann als Fehlermeldung: Verwendung der nicht zugewiesenen lokalen Variablen "strFiller" also in der Zeile: strFiller += s;
    0
     

  4. 11.09.2012, 18:36
    #4
    Zitat Zitat von yjeanrenaud Beitrag anzeigen
    Code:
    string strFiller = "";
    foreach (string s in words)
    
                 {
    
                    strFiller += s;                          // fügt jedes mal s zu strFiller hinzu.
                    strFiller = strFiller+s;                // geht genau so, ist nur nicht so hübsch ;) 
    
                }
    myTextBlock3.Text = strFiller;                     //und nun ausgeben
    Kleine Korrektur - bei der Deklaration wird jetzt strFiller mit einem Leerstring initialisiert, dann sollte es gehen.
    1
     

  5. 11.09.2012, 18:48
    #5
    jaa, danke jetzt klappt das ja schon mal FAST jetzt gibt er mir, wenn ich zum Beispiel "Hallo+wie+geht+es+dir" schreibe. Hallowiegehtesdir.
    wenn ich es richtig verstanden habe, habe ich doch die einzelnen Wörter in Arrays gespeichert, oder? also kann ich diese aus word [0] als einzelnes wort ausgben? Geht dieses dann auch aus einem mix aus Zahlen und Wörtern? zB. hallo3+wie2+geht1+es4+dir5 in hallo wie geht es dir und 3 2 1 4 5 ?
    0
     

  6. ja kannst du, genau.
    0
     

  7. 12.09.2012, 12:15
    #7
    Na ja, bei nem int[] Array muss er dann halt erst noch ToString() aufrufen, sonst wird das Plus nämlich die Zahlen addieren statt sie hintereinanderzuhängen. Hast du jedoch die Zahlen in einem String[] Array geht es so wie hier beschrieben.

    arr[0].ToString() wandelt dir wenn arr ein Int-Array ist den Wert an der Stelle 0 zu einem String um
    Int32.Parse(arr[0]) wandelt dir wenn arr ein String-Array ist den String an der Stelle 0 zu einem Int um (vorrausgesetzt da steht eine Zahl drinnen in einem Format, dass geparst werden kann - wenn der String jetzt aber "Hallo" ist dann gibts ne Exception).
    0
     

Ähnliche Themen

  1. Hilfe/Fehler beim laden von Android
    Von Mille1986 im Forum HTC HD2 Android
    Antworten: 12
    Letzter Beitrag: 23.10.2010, 14:10
  2. Hilfe beim Installieren von Apps
    Von Unregistriert im Forum Android Allgemein
    Antworten: 4
    Letzter Beitrag: 22.04.2010, 09:38
  3. Antworten: 1
    Letzter Beitrag: 05.10.2009, 15:08
  4. Brauche Hilfe beim installieren von Spiel.
    Von Piega85 im Forum Touch HD Fun
    Antworten: 12
    Letzter Beitrag: 08.05.2009, 20:49
  5. Brauche Hilfe beim Installieren von G-Flow
    Von Rhaki im Forum HTC Touch Diamond
    Antworten: 3
    Letzter Beitrag: 27.10.2008, 20:37

Stichworte