删除* .txt文件中的特定行 [英] Erase a specific line in a *.txt file

查看:105
本文介绍了删除* .txt文件中的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。

如何删除* .txt文件中的特定行?

提前致谢。


-

Xero

http:// www.chezjeff.net

我的个人门户网站

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

--
Xero

http://www.chezjeff.net
My personal web portal

推荐答案

Jeff,


您不能直接在磁盘上的文件中执行此操作,但是当您已经过了比它更贵的
时。


您不能这样做在文本文件中,当它不是真正的行时(我开始用

这是因为它逐步显示它更好)。在内存中我知道的最简单的方式是:b $ b \\\

mytext.text = mytext.text.replace( " myline to delete","")

///


如果是行,你可以通过添加相同的方式来实现使用的

换行作为示例

\\\

mytext.text = mytext.text.replace(" myline to delete" ;& VBCRLF,")

///

我从来没有按照上面的方式在一个程序中做过但是有了这个想法写的这个


当它没有被读取时,你可以只读取和写入行,检查一行的

内容而不是写回来。


你必须删除输入并在最后重命名输出文件。


我虽然在那个streamreader streamwritter中有一些样本

此页面中的样本集合。

http://msdn.microsoft.com/library/de...classtopic.asp


我希望这有帮助吗?


Cor
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


" Xero" < jeff _ @ _ chezjeff _._ net(remove_underscores_and_this)> schrieb:
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> schrieb:
如何删除* .txt文件中的特定行?
How do you erase a specific line in a *.txt file?




您可能需要阅读文件行-by-line,然后删除该行,

将这些行写回文件。您可以使用''FileStream.SetLength''来设置

文件的长度。要读取文件,请使用''System.IO.StreamReader'',

来编写''System.IO.StreamWriter''。


正在阅读文本文件逐行或带有进度指示器的块状

< http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en


-

Herfried K. Wagner [MVP]

< http://dotnet.mvps.org/>



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



" Xero" < jeff _ @ _ chezjeff _._ net(remove_underscores_and_this)>写了

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote
你好。
如何删除* .txt文件中的特定行?
Hello.
How do you erase a specific line in a *.txt file?




你会这样做擦除视频录制中的商业广告,

你要么必须拼接磁带(不能用硬盘驱动器)

或复制整个程序到一个新的磁带,并在此过程中跳过商业

。这就是磁存储的运作方式....


要删除文件中的数据,你必须使用所需的

数据构建一个新文件省略。如果你可以使用新数据覆盖原始文件,那么很好,

但更多时候你只需要创建一个新文件并只复制你想要保留的那些

部分。 ..


LFS



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


这篇关于删除* .txt文件中的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆