winforms - Deleting some content from the text file in c# -


i have text file called load.txt contains approximately 200 lines. have checkbox, if checked want create new file had first 100 lines load.txt. , using c# program. real requirement have delete line 110 201.and code below , because of reason deleting line 1 92. dnt know whats happening.

            string line = null;              string tempfile = path.gettempfilename();             string filepath = savefiledialog1.filename;              int line_number = 110;             int lines_to_delete = 201;              using (streamreader reader = new streamreader(sqlconnectionstring))             {                 using (streamwriter writer = new streamwriter(savefiledialog1.filename))                 {                     while ((line = reader.readline()) != null)                     {                         line_number++;                          if (line_number <= lines_to_delete)                             continue;                          writer.writeline(line);                     }                 }             } 

so figured out issue. next issue that: updating of variables in text file. before code alright . code conflicting delete lines code. if able delete lines m not able update variables.

my code is:

file.writealllines(savefiledialog1.filename, system.io.file.readline(sqlconnectionstring).take(110)); file.writealltext(savefiledialog1.filename, filecontents); 

file.writealllines("new.txt", file.readlines("load.txt").take(100)); 

after update...

var desired = file.readlines("load.txt")                   .take(110)  // "and want keep 1-110" -- op                   .select(line => updateline(line));  // "and want update variables between 1-110" -- op  file.writealllines("new.txt", desired);  ...  static string updateline(string given) {      var updated = given;      // other ops      return updated; } 

msdn file.writealllines
msdn file.readlines


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -