c# - Text shown in single line in notepad -
i having issue regular notepad.
if open file in wordpad, displays text rich textbox correctly (with line breaks textbox). in notepad it's 1 huge line, how can when writing file, recognizes linebreaks in rich text box?
what open notepad file contains block of text , goes richtextbox1.
copy text first text box , write in richtextbox2 text first richtextbox , copied text stripped vowels (copytext) write second notepad file (_parsed.text).
string chosen_file = "c:\\_testfile.txt"; string second_file = "c:\\_parsed.txt"; string wholetext = ""; private void mnuopen_click(object sender, eventargs e) { //add data text file rich text box richtextbox1.loadfile(chosen_file, richtextboxstreamtype.plaintext); //read lines of text in text file string textline = ""; streamreader txtreader; txtreader = new streamreader(chosen_file); { textline = textline + txtreader.readline() + " "; } //read line until there no more characters while (txtreader.peek() != -1); richtextbox1.text = textline; txtreader.close(); } } private void write(string file, string text) { //check see if _parsed file exists //write _parsed text file using(streamwriter objwriter = new streamwriter(file)) { objwriter.write(text); objwriter.close(); } } private void newsummarymethod(string copytext) { //write richtextbox2 relevant text copytext = richtextbox1.text; wholetext = richtextbox1.text + copytext write(second_file, wholetext); } private void btn1_click(object sender, eventargs e) { newsummarymethod(copytext); }
first of try separate data , presentation.
if have file lines in can read file.readlines method
var lines = file.readlines("file1.txt");
after can show lines on textbox, console whatever else.
when you're appending text, update lines collection
lines.addrange(secondlistoflines);
and save updated file using file.writealllines method:
file.writealllines(lines, "file2.txt");
Comments
Post a Comment