c# - Setting a string from one destination to another -
i want include string "oldsummary"
in second richtextbox, of summary's functionality belongs streamread
after opening file. there way when btn1 button clicked, display oldsummary
string? @ moment it's blank due it's global string set "" want display oldsummary
string set in mnuopen
button.
string oldsummary = ""; private void mnuopen_click(object sender, eventargs e) { //load file code remove example goes here… //add data text file rich text box richtextbox1.loadfile(chosen_file, richtextboxstreamtype.plaintext); //read lines of text in text file string textline = ""; int linecount = 0; system.io.streamreader txtreader; txtreader = new system.io.streamreader(chosen_file); { textline = textline + txtreader.readline() + " "; linecount++; } //read line until there no more characters while (txtreader.peek() != -1); //seperate characters in order find words char[] seperator = (" " + nl).tochararray(); //number of words, characters , include line breaks variable int numberofwords = textline.split(seperator, stringsplitoptions.removeemptyentries).length; int numberofchar = textline.length - linecount; string divider = "------------------------"; //unprocessed summary string oldsummary = "word count: " + numberofwords + "characters count: " + numberofchar + divider; txtreader.close(); } private void btn1_click(object sender, eventargs e) { string wholetext = ""; string copytext = richtextbox1.text; wholetext = oldsummary + copytext; richtextbox2.text = wholetext; }
try replacing:
string oldsummary = "word count: " + numberofwords + "characters count: " + numberofchar + divider;
with:
oldsummary = "word count: " + numberofwords + "characters count: " + numberofchar + divider;
so assign value class field used in btn1_click
.
Comments
Post a Comment