Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!!!

Posted
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.
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...