c# - extract lines from a flowdocument in a richtextbox starting with specific words WPF -


i'm new wpf , make text analysing tool. know how import text rich textbox , format properly, want run method extracts lines in flowdocument start int or ext , place them in listbox. seems quite easier in winforms in wpf.

is there can guide me this?

i wish provide code flowdocument new me wpf.

i have written code snippet collect lines begin int or ext. sure code not optimal, because not practised richtextbox, think easy understand.

private list<string> collectlines() {     textrange textrange = new textrange(         // textpointer start of content in richtextbox.         testrichtextbox.document.contentstart,         // textpointer end of content in richtextbox.         testrichtextbox.document.contentend);      // text property on textrange object returns string      // representing plain text content of textrange.      var text = textrange.text;      list<string> resultlist = new list<string>();      // collect line begin int or ext     // or use .contains if line begin tab (\t), spacing or whatever     using (stringreader sr = new stringreader(text))     {         var line = sr.readline();         while (line != null)         {              if (line.startswith("int") || line.startswith("ext"))             {                 resultlist.add(line);             }              line = sr.readline();         }     }      return resultlist; } 

maybe can find out how can put list listbox :)


Comments