poffin
8 years agoOccasional Contributor
Remove text from a file?
All I want to do is remove a string from a certain text file. Here's the best way I can think to do that:
1. Rename file.
2. Open a new empty text file in its place.
3. Read original file, and write to the empty file line-by-line until I come across the text I want to remove.
4. Skip that text, and keep writing to the new file until I get to the end.
Are there any simpler or more elegant ways just to remove a few characters? I could overwrite them, but that only works if the output file contains more characters than the input. All I want to do is delete, not add anything.