c# - Reading in lines of text from a rich text box -


i making small application myself concatenates statements based on text entered couple rich text boxes on form.

one text box may have 10-20 lines of text, , each line own separate entry, need able read text line-by-line.

however, when researching wpfs, have seen 1 statement on net in regards reading text , reading content of box start finish. somehow loop through or separate line-by-line.

according msdn, extract text wpf rich text box string, need use:

string stringfromrichtextbox(richtextbox rtb) {     textrange textrange = new textrange(       // textpointer start of content in richtextbox.       rtb.document.contentstart,        // textpointer end of content in richtextbox.       rtb.document.contentend     );      // text property on textrange object returns string      // representing plain text content of textrange.      return textrange.text; } 

however, if @ rich text box, see text inside list of values, instance, 1 box may below:

000423523  324  93489290099  823342342  0003242342  44400298889 

i want able read values line line within richtextbox, in wpf, there doesn't seem richtextbox1.lines option.

you can use string.split() method split richtextbox text line-break , exclude empty lines result set, example :

string[] lines =          stringfromrichtextbox(rtb).split(new[]{environment.newline}                                           , stringsplitoptions.removeemptyentries);  foreach (var line in lines) {     messagebox.show(line); } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -