c# - How to split a regex and not display text in text file in one line -
i have 2 little question struggling with. both dealing lines really.
1: how can place following regex code split()?
regex(@"\r\n|\n|\r", regexoptions.singleline) int num = copytext.split().length - 1; //copytext string
2: when write text file rich text box, text in text file displayed on 1 line. how can text displayed looks in rich text box?
private void write(string file, string text) { //check see if _parsed file exists if (file.exists(file)) { //write _parsed text file using(streamwriter objwriter = new streamwriter(file)) { objwriter.write(text); objwriter.close(); } } else { messagebox.show("no file named " + file); } } private void btnreplace_click(object sender, eventargs e) { // replace -ing ending words xxxxxx code goes here... //write richtextbox2 wholetext = richtextbox1.text + oldsummary + copytext + newsummary; write(second_file, wholetext); richtextbox2.text = wholetext; }
for 1st problem try this:
int num = regex.split(copytext, @"\r\n|\n|\r").count - 1;
see: msdn
for 2nd 1 try:
file.writealllines(filename, richtextbox.lines);
and please read possible dublicate: from richtextbox text files, line after line
richtextbox.savefile(string path, richtextboxstreamtype);
built-in function
Comments
Post a Comment