Erase a specific line in a *.txt file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello.
How do you erase a specific line in a *.txt file?
Thanks in advance.
 
Jeff,

You cannot do that directly in a file on disk, however when you have readed
that than it is.

You cannot do that in a textfile when it are not real lines (I start with
this because that shows it better step by step ). In memory the most simple
way I know is.
\\\
mytext.text = mytext.text.replace("myline to delete","")
///

When it is are lines you can do it in the same way by adding the used
linefeed as example
\\\
mytext.text = mytext.text.replace("myline to delete" & VBCRLF ,"")
///
I never did it the way above in a program however got the idea writting this

When it is not readed, you can just read and write the lines, check the
contents of a line and not write that one(s) back.

You have to delete the input and rename the output file at the end.

I though there are for that some samples in that streamreader streamwritter
collection of samples in this page.

http://msdn.microsoft.com/library/d.../html/frlrfsystemiostreamreaderclasstopic.asp

I hope this helps?

Cor
 
Xero said:
How do you erase a specific line in a *.txt file?

You may want to have to read the file line-by-line, then remove the line and
write the lines back to the file. You can use 'FileStream.SetLength' to set
the length of the file. For reading the file, use 'System.IO.StreamReader',
for writing 'System.IO.StreamWriter'.

Reading a text file line-by-line or blockwise with a progress indicator
<http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en
 
Xero said:
Hello.
How do you erase a specific line in a *.txt file?

The same way you would erase a comercial in a video recording,
you'd either have to splice the tape (can't do that with a hard drive)
or copy the whole program to a new tape, and skip over the commercial
in the process. That's how magnetic storage operates....

To erase data from a file, you have to build a new file with the desired
data omitted. If you can overwrite the original file with new data, fine,
but more often you will simply create a new file and copy only those
portions you want to keep....

LFS
 
Larry Serflaten said:
How do you erase a specific line in a *.txt file?
[...]
To erase data from a file, you have to build a new file with the desired
data omitted. If you can overwrite the original file with new data, fine,
but more often you will simply create a new file and copy only those
portions you want to keep....

ACK. But there is one drawback with the latter method: The file's creation
timestamp will change.
 
Herfried,
ACK. But there is one drawback with the latter method: The file's
creation
timestamp will change.
Never made a video tape as in Larry's sample probably?

Cor
 
Herfried said:
Larry Serflaten said:
How do you erase a specific line in a *.txt file?

[...]
To erase data from a file, you have to build a new file with the desired
data omitted. If you can overwrite the original file with new data, fine,
but more often you will simply create a new file and copy only those
portions you want to keep....


ACK. But there is one drawback with the latter method: The file's creation
timestamp will change.

So.. just change it back.. I'm sure there's an API for that somewhere.
Touch.exe brings back memories :)
 
Rinze,

In my opinion is this no answer.
So.. just change it back.. I'm sure there's an API for that somewhere.
Touch.exe brings back memories :)

Can you give us the link to that API or tell how it works.

Cor
 
Cor said:
Rinze,

In my opinion is this no answer.

What? I can't point out that there might be an API for that? Im my
opinion it is an answer. It might not give a "here's the fix" kind of
answer.
Can you give us the link to that API or tell how it works.

Cor

I don't know it off hand, but with older progamming languages there was
touch.exe to change the date/time of a file. I used that to give all
files of a program in those days the same date/time, or sneak a version
into the time (like 6:32 is version 6, subverion 32). So there must be
an API to change the date/time of a file.
 
Rinze,

I don't know it off hand, but with older progamming languages there was
touch.exe to change the date/time of a file. I used that to give all files
of a program in those days the same date/time, or sneak a version into the
time (like 6:32 is version 6, subverion 32). So there must be an API to
change the date/time of a file.

Changing the datetime of a file is quiet different from changing "1 april
2004" to "5 december 2004" as a text in a file.

For the first you can by instance use this one
http://msdn.microsoft.com/library/d...miofilesysteminfoclasslastaccesstimetopic.asp

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top