delphi 在文本文件中添加和删除
我想在固定的位置添加一行记录
if Pos('Str',Strtext) > 0 then
//我要在这里添加一行
删除的时候也是
if Pos('Str',Strtext) > 0 then
//删除包含'Str'的这一行
这2个问题怎么做啊
[解决办法]
将Strtext: string;换为Strtext: TStringList;
然后将文本文件中的一行行读到Strtext中,用Strtext.Add();
在for循环Strtext,
添加:
i := 0;
while i < Strtext.Count do
begin
if Pos('Str',Strtext[i]) > 0 then
begin
Strtext.Insert(i, '要插入的字符串');
Inc(i);
end;
Inc(i);
end;
删除:
i := 0;
while i < Strtext.Count do
begin
if Pos('Str',Strtext[i]) > 0 then
Strtext.Delete(i)
else
Inc(i);
end;