delphi中怎样替换整个项目中的某个字符串?

csdyyr 2010-04-22 05:30:34
因为有N个文件中包含需要替换的字符串,如果逐个替换太麻烦了,请问有没有简单的方法?
...全文
839 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
mathsfan 2010-04-23
  • 打赏
  • 举报
回复
以前自己写个一个这方面的小软件,LZ可以自己写的一个啊,思路无非是遍历文件夹然后搜索替换...
火龙岛主 2010-04-23
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 keiy 的回复:]
安装一个untraedit,它可以在某目录下,替换所有某一类型文件的
[/Quote] 推荐
柯本 2010-04-23
  • 打赏
  • 举报
回复
安装一个untraedit,它可以在某目录下,替换所有某一类型文件的
shuaialang 2010-04-23
  • 打赏
  • 举报
回复
好吧,我承认我发错帖子了。SORRY。。
shuaialang 2010-04-23
  • 打赏
  • 举报
回复
LZ要毕业设计的话加我QQ我帮你做了 20589816
风之谷 2010-04-23
  • 打赏
  • 举报
回复
cnpack
shuaialang 2010-04-23
  • 打赏
  • 举报
回复
首先使用


function FindFile(Path: string): string; {搜索文件夹和文件}
var
Sr: TSearchRec;
CommaList: TStringList;
s: string;
dt: TDateTime;
begin
commalist := Tstringlist.Create;
try
Findfirst(path + '*.*', faAnyFile, sr);
if ((Sr.Attr and faDirectory) > 0) and (Sr.Name <> '.') then
begin
dt := FileDateToDateTime(sr.Time);
s := FormatDateTime('yyyy-mm-dd hh:nn', dt);
commalist.add('*' + s + sr.name);
end;
while findnext(sr) = 0 do
begin
if ((Sr.Attr and faDirectory) > 0) and (Sr.Name <> '..') then
begin
dt := FileDateToDateTime(sr.Time);
s := FormatDateTime('yyyy-mm-dd hh:nn', dt);
commalist.add('*' + s + sr.name);
end;
end;
FindClose(sr);
FindFirst(path + '*.txt', faArchive + faReadOnly + faHidden + faSysFile, Sr);
if Sr.Attr <> faDirectory then
begin
dt := FileDateToDateTime(sr.Time);
s := FormatDateTime('yyyy-mm-dd hh:nn', dt);
commalist.add('\' + s+ Format('%.0n', [sr.Size / 1]) + '|' + sr.name);
end; //Inttostr(
while findnext(sr) = 0 do
begin
if (sr.Attr <> faDirectory) then
begin
dt := FileDateToDateTime(sr.Time);
s := FormatDateTime('yyyy-mm-dd hh:nn', dt);
commalist.add('\' + s +Format('%.0n', [sr.Size / 1]) + '|' + sr.name);
end;
end;
FindClose(Sr);
except
end;
Result := commalist.Text; //Result是消息的 定义
commalist.Free;
end;

得到txt文件列表


再利用 memo.loadfromfile 逐一加载并且使用Replace替换内容不就可以啦?我没理解错吧?
fang 2010-04-22
  • 打赏
  • 举报
回复
写代码自己检索pas文、窗体文件替换,以为又是宏的处理问题。
SQLDebug_Fan 2010-04-22
  • 打赏
  • 举报
回复
DELPHI中不提供这样的编辑功能,可以自己写个工具,查找替换就可以了。
devhp 2010-04-22
  • 打赏
  • 举报
回复
如果樓主是非必將此功能置入自己程序的話。直接DOWN一個幾百K的批量文本替換工具,比較省事,

csdyyr 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 merrymin 的回复:]

引用楼主 csdyyr 的回复:
因为有N个文件中包含需要替换的字符串,如果逐个替换太麻烦了,请问有没有简单的方法?

我先搜索到当前所有文件需要替换的字符串,然后再一个个地Ctrl + V
[/Quote]
你这方法更慢了,可以Ctrl+R..., 确定之后可以在其它文件中直接F3就可以了。
merrymin 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 csdyyr 的回复:]
因为有N个文件中包含需要替换的字符串,如果逐个替换太麻烦了,请问有没有简单的方法?
[/Quote]
我先搜索到当前所有文件需要替换的字符串,然后再一个个地Ctrl + V
csdyyr 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hongss 的回复:]

把这个字符串变成一个全局变量,替换的时候只需要替换这个字符串的赋值就可以了。

可以用Replace
[/Quote]
可惜现在不是你所说的情况。
hongss 2010-04-22
  • 打赏
  • 举报
回复
把这个字符串变成一个全局变量,替换的时候只需要替换这个字符串的赋值就可以了。

可以用Replace

5,936

社区成员

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

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