I need to find out how to cut text and insert text into a textfile.....I know about StreamReader and StreamWriter but i dont think any of these will do unless theres some method in the class that I dont know about.

I want to be able for example read from script.txt but before it is printed and the user can see it, I remove certain things they dont want which would be specified by checkbox such as if chechbox1 is checked then it will cut out the line I specify in the code such as line 7...is there anyway to do this?

The only way I know of is to rewrite the file before Notepad (or some other program) gets it. I doubt Notepad.exe has a hook where you can intercept the file that it reads.

Try logic of below given code ....you can remove particular line in notepad with the help of Streeam Reader and Stream Writer...

var tempFile = Path.GetTempFileName();
var linesToKeep = File.ReadLines(fileName).Where(l => l != "removeme");

File.WriteAllLines(tempFile, linesToKeep);

File.Delete(fileName);
File.Move(tempFile, fileName);

That works with normal text file, has nothing to do with Notepad.exe.

i've re-read the posts above and there is no reference to the notepad application itself except for the title but maybe the word "notepad" means "textfile". The reason why i say this is because pilot122x is talking about checkboxes so it leads me to beleive this process is happening outside of the notepad application itself.

This article has been dead for over six months. Start a new discussion instead.