怎么对所选择的文本文件内容进行操作?
例如 c:\1.txt
其内容为
123
123
.
.
.
.
321
123
此类。我想先对于123进行查找后再对他进行替换?请教高手。
例如 c:\1.txt
其内容为
123
123
.
.
.
.
321
123
此类。我想先对于123进行查找后再对他进行替换?请教高手。
解决方案 »
- Delphi 如何创建Cookie文件。
- tcxdbcombobox控件!!!极其严重的问题!!
- 数据库数据导入EXCEL中时生成多个文件问题?
- dbgrid中怎样选择多条记录进行删除,请高手赐教
- 101 分问:关于COM事件,D5、6开发指南的一点疑问!
- 如何汉化ExpressBars v4.2中的dxBarCustForm!急!!!!!
- 来者有分!!!
- 小二给大家上菜啦(1)??:提交不了更新的数据了!
- 用Delphi或pascal开发windows ce下的PDA应用程序?
- delphi中有没有自动完成关键字的功能?
- 请问onprint是在什么情况下运行的
- 为什么记录的窗口位置,和屏幕实际情况不同?
比如Memo
你先把文本的内容导入到Memo里
然后再对Memo里的内容进行操作
达到要求后
在SavetoFile导出文件
st:TStringList;
i:Integer;
begin
st:=TStringList.Create;
st.LoadFromFile('c:\1.txt');
if st.Find('123',i) then
st.Strings[i]:='567';
st.SaveToFile('c:\1.txt');
end;
var
st:TStringList;
i:Integer;
begin
st:=TStringList.Create;
st.LoadFromFile('c:\1.txt');
if st.Find('123',i) then
st.Strings[i]:='567';//567为你需要替换的东西
st.SaveToFile('c:\1.txt');
st.free;
end;
上面忘记释放了
procedure FileTextReplace(AFileName, NewFileName, OldStr, NewStr: string);
var
sl: TStringList;
begin
sl := TStringList.Create;
try
sl.LoadFromFile(AFileName);
sl.Text := StringReplace(sl.Text, OldStr, NewStr, [rfReplaceAll]);
sl.SaveToFile(NewFileName);
finally
sl.Free;
end;
end;