c# - Adding text to a file is displayed in one long line -
i having issue when write text second file, display fine in wordpad includes linebreaks
, in notepad text copytext
, richtextbox1.text
appear in 1 long line.
how can fix this? if can include code snippet code appreciated can see have done , changed , can keep reference futr use.
my code below take text text file (testfile.txt
) , insert richtextbox1
, when click on button, text copied richtext box2
, written in second file (_parsed.txt
).
did message box on text line , displays text without line break. i'm not sure if issue need deadline tomorrow , thing need sort out , i'm done.
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); }
the problem never adding new line file in code. using objwriter.write(text);
not generate new line.
you can use objwriter.writeline(text);
instead , automatically add new line character @ end.
i think difference in viewing file because "word wrap" option turned on in "wordpad" , causes break long line multiple line.
Comments
Post a Comment