如何读取文本文件的某行,并将这一行删除!

s_x_d 2003-05-23 10:58:12
如有这样的文本:

.
.
.
.
.
12345
123456
1234567
.
.
.
如果要删除1234567这一行,该怎么处理!(不是固定的行)
...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
timelyraining 2003-05-23
  • 打赏
  • 举报
回复
var
i:integer;
begin
memo1.Lines.LoadFromFile('c:\ts.txt');
for i:=0 to memo1.Lines.Count-1 do
if memo1.Lines.Strings[i] ='12345' then
begin
memo1.Lines.Delete(i);
break;
end;
memo1.Lines.SaveToFile('c:\ts.txt');

注意:需要一个tmemo组件
coreblood 2003-05-23
  • 打赏
  • 举报
回复
var
str1:tstrings
i:integer;
begin
str1:=tstringlist.creat;
str1.LoadFromFile('c:\xxx.txt');
for i:=1 to str1.count do
begin
if str1[i]:='1234567' then
str1[i]:='';
end;
str1.savetofile('c:\xxx.txt');
end;

pingshx 2003-05-23
  • 打赏
  • 举报
回复
文本文件不大的话。

function delete_line(line:string;filename);
var
s:strings;
count:integer;
begin
s:=tstringlist.create;
s.loadfrom(filename);
count:=0;
while count<s.count-1 do
if s[count]<>line then inc(count);
if count=s.count-1 then s[count]:=' ' else
把后面的覆盖前面的。
s.savefile(filename);
s.free.
老兄这么点分??????????


ityaa 2003-05-23
  • 打赏
  • 举报
回复
一个笨方法:用MEMO将文件读入,循环查找每行,用POS查找1234567是否在某一行中,如果在,将这一行删除,然后将文件存盘。

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧