问题:DELPHI7对txt文件的读写问题
描述:delphi
代码如下
procedure TForm1.Button1Click(Sender: TObject);
var
f:textfile;
s,c:string;
begin
assignfile(f,'C:\123.txt');
reset(f);
while not eof(f) do
begin
readln(f,s); //是不是因为这里是只读方式打开的,所以无法写入?
c:=copy(s,1,5);
if c = 'abcde' then
begin
//table1.InsertRecord([copy(s,1,6),null,copy(s,7,6),null]);
delete(s,7,6);
end;
end;
closefile(f);
end;
end.
我本意是想当读到abcde时 就把本行内从第7个位置向后删除6位
是不是DELETE(S,7,6) 中s不对?应该要怎么改?
感觉是语法没有用对。
解决方案1: 修改代码如下,已经通过测试:
procedure TForm1.Button1Click(Sender: TObject);
var
f:textfile;
FileName,s,c:string;
MyList:TStringlist;
begin
MyList:=TStringlist.Create;
FileName:='C:\123.txt';
assignfile(f,FileName);
reset(f);
while not eof(f) do
begin
readln(f,s);
c:=copy(s,1,5);
if c = 'abcde' then
begin
delete(s,7,6);
end;
MyList.Add(S);
end;
closefile(f);
MyList.SaveToFile(FileName);
MyList.Free;
end;
- 明星图片
- 相关文章
-
联系邮箱:mxgf168#qq.com(#改为@)