c# - Printing the Processing File followed by the <id> -


private void button1_click(object sender, eventargs e) {     string value = textbox1.text;     string[] lines = value.split(environment.newline.tochararray());      foreach (string l in lines)     if (l.indexof("processing")==0)     {        textbox4.text = textbox4.text + l + environment.newline;     }      matchcollection matches2 = regex.matches(value, "\"([^\"]*)\"");     foreach (match match2 in matches2)     {         foreach (capture capture2 in match2.captures)         {                           textbox4.text = textbox4.text + environment.newline + capture2.value;             }     } }    

my input is:-

processing \\users\\bhargava\\desktop\new.txt  <"dfgsgfsgfsgfsgfsgfsgfs">  processing \\users\\bhargava\\desktop\\new.txt  <"dfgsgfsgfsgfsgfsgfsgfs">  processing \\users\\bhargava\\desktop\new.txt  processing \\users\\bhargava\\desktop\\new.txt 

i need output :-

processing \\users\\bhargava\\desktop\new.txt  "dfgsgfsgfsgfsgfsgfsgfs"  processing \\users\\bhargava\\desktop\\new.txt  "dfgsgfsgfsgfsgfsgfsgfs"  processing \\users\\bhargava\\desktop\new.txt  processing \\users\\bhargava\\desktop\\new.txt 

i getting :-

processing \\users\\bhargava\\desktop\new.txt   processing \\users\\bhargava\\desktop\\new.txt   processing \\users\\bhargava\\desktop\new.txt  processing \\users\\bhargava\\desktop\\new.txt  "dfgsgfsgfsgfsgfsgfsgfs"  "dfgsgfsgfsgfsgfsgfsgfs" 

please me out!

there's missing pair of curly braces in code. first foreach needs curly braces encapsulate code comes afterwards. without it grabs next statement , repeats each of elements of lines. that's why you're getting each of lines starts "processing" followed 2 matches of id. try instead:

private void button1_click(object sender, eventargs e) {         string[] lines = value.split(environment.newline.tochararray());          foreach (string l in lines)         {             if (l.indexof("processing")==0)             {                textbox4.text = textbox4.text + l + environment.newline;             }              matchcollection matches2 = regex.matches(l, "\"([^\"]*)\"");             foreach (match match2 in matches2)             {                 foreach (capture capture2 in match2.captures)                 {                                   textbox4.text = textbox4.text + environment.newline + capture2.value;                     }             }         }     }    

so in example added curly braces mentioned, , got rid of value , instead told regex search current line. if search value each time you'll end way more repetitions of id desired output says you're looking for.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -