0

What I'm doing is reading a file line by line, and then comparing each line that's read with a pre-specified string. If it's a match, I want to remove the code from the class I'm inspecting, starting at the line that matched the pre-specified string until a designated location I've identified is reached. What I'm struggling with is how to implement a removal. I've written methods to add, subtract, adjust, etc., but never to just completely remove a chunk of code, so I don't know how to procede. I bet there's some simple way to accomplish this, but it's escaping me right now.

Jremy
  • 73
  • 1
  • 1
  • 8
  • @Tim Lehner, you're right it is a duplicate...Although I didn't realize that what I was looking for was just to simply write to another file if a condition was found. – Jremy Feb 11 '13 at 19:48

1 Answers1

2

It sounds like you are asking "How do I remove something from the middle of a file?" - it just happens to be source code.

The easiest way is to create a temp file (or in memory stream) to which you write all the content you want to keep and then when you are done processing the old file you over-write it with the contents you choose to keep.

Robert Horvick
  • 3,966
  • 21
  • 18