mwmosu

mwmosu

  • NA
  • 10
  • 0

loop through a .doc file and delete specified lines

Jun 3 2004 5:58 PM
I am trying to loop through a .doc file and delete specified lines. Here is the code I have so far: try { // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. using (StreamReader sr = new StreamReader(tmpdir + newfilename)) { File.OpenWrite(tmpdir + newfilename); FileInfo f = new FileInfo(tmpdir + newfilename); string line; int c = 0; string sentinel="start"; // Read lines from the file until the end of the file is reached. if (f.Length > 0) { while (f.Length >= c) { if (line.IndexOf("GOTO 9988") == 0) { sentinel = "stop"; } else if (line.IndexOf("<9988>") == 0) { sentinel = "start"; } if (sentinel == "start") { //HERE IS WHERE THE CODE GOES TO REMOVE //ANY LINE THAT IS READ WHEN SENTINEL = START } c++; } } catch .......... } } Any help is appreciated.