laroberts Posted July 13, 2005 Posted July 13, 2005 I am trying to figure out how to remove a line of text from a txt file from within VB.NET. This is what my current code looks like, I put a line that says ***** where I know the delete command should go. I can not figure out how to do this. The item that I want to delete is contained with in JobFile dim FILE_NAME as string = (String.format(H:\Operations\{0}\{1}\Master.txt", DayOfWeek, ShiftAssigned)) dim objwriter as new system.io.streamwriter(FILE_NAME, true) dim jobfile as string = CStr(Me.ComboBox3.SelectedItem) ***** The delete command should go here!!!***** Beep() MsgBox("Master List Updated.") Thank you!!! Quote
thenerd Posted July 13, 2005 Posted July 13, 2005 You'll want to read the entire text file into a string variable, delete the line of text from the string variable, then, overwrite the textfile with a new textfile (same name) that contains that string that you just edited. Quote
laroberts Posted July 14, 2005 Author Posted July 14, 2005 Uuuumm.... Ummmm.... ok..... How the hell do I do that? Sorry, really new to all this. Thank you Quote
jmcilhinney Posted July 14, 2005 Posted July 14, 2005 Read the file in using a StreamReader. You can read the whole file in one go using ReadToEnd, or line by line using ReadLine. Once you have a String variable or array, you can simply replace the appropriate line using whatever type of string manipulation seems most appropriate. Finally, write the file back out again using a StreamWriter. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.