473,408 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Erase a specific line in a *.txt file

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

--
Xero

http://www.chezjeff.net
My personal web portal
Nov 21 '05 #1
11 3457
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/de...classtopic.asp

I hope this helps?

Cor
Nov 21 '05 #2
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> schrieb:
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

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 21 '05 #3

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote
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
Nov 21 '05 #4
"Larry Serflaten" <se*******@usinternet.com> schrieb:
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 K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #5
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
Nov 21 '05 #6
"Cor Ligthert" <no************@planet.nl> schrieb:
Never made a video tape as in Larry's sample probably?


I don't have and never had TV/video recorder.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #7
Herfried K. Wagner [MVP] wrote:
"Larry Serflaten" <se*******@usinternet.com> schrieb:
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 van Huizen
C-Services Holland b.v.
Nov 21 '05 #8
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
Nov 21 '05 #9
Cor Ligthert wrote:
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.
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


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 van Huizen
C-Services Holland b.v.
Nov 21 '05 #10
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/de...stimetopic.asp

Cor
Nov 21 '05 #11
Cor Ligthert wrote:
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/de...stimetopic.asp

Cor

ffs

I looked it up. API is called SetFileTime

--
Rinze van Huizen
C-Services Holland b.v.
Nov 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kaede | last post by:
Hi all, I recently came across the following code: // some data struct Data { // ... some data }; // a list to hold the data vector<Data> dataList;
9
by: BCC | last post by:
I have the following code, where good_list is a vector of CUnits: int high_cutoff = 10; vector<CUnit>::iterator it; for (it = good_list.end(); it != good_list.begin(); --it) { CUnit* ccu = it;...
5
by: Angus Leeming | last post by:
Dinkumware's online STL reference http://tinyurl.com/3es52 declares std::map's overloaded erase member functions to have the interface: map::erase iterator erase(iterator where); iterator...
0
by: Tero Toivanen | last post by:
Dear experts, I am doing code to Solaris 9 system with C++. I get every now and then segmentation fault in the following code that removes heading and trailing white spaces (mLineStr is of...
1
by: Tero Toivanen | last post by:
Dear experts, I am doing code to Solaris 9 system with Forte 6 Update 2 C++ compiler.. I get every now and then segmentation fault in the following code that removes heading and trailing...
5
by: Billy Patton | last post by:
I have a polygon loaded into a vector. I need to remove redundant points. Here is an example line segment that shows redundant points a---------b--------c--------d Both b and c are not...
20
by: Tom van Stiphout | last post by:
I'm about to write a function like below, which I'm going to call a lot of times. So I care about possible memory leaks. I think whether I should use Erase or not depends on whether Split creates...
8
by: olanglois | last post by:
Hi, I was asking myself to following question. What is better to erase an element from a STL map: calling (option #1) size_type erase(const key_type& k) or calling (option #2)
16
by: Frank Neuhaus | last post by:
Hi I have some std list, I'd like to traverse. During the traversal, I want to conditionally delete some objects. My code for that is like this right now: for (std::list<myStruct>::iterator...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.