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.
Asked
Active
Viewed 118 times
1 Answers
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
-
@Bubbafat--thanks for pointing me in the right direction! Much appreciated. – Jremy Feb 11 '13 at 19:47