读书人

Delphi中怎么打开一个文件在里面查找

发布时间: 2012-02-27 10:00:22 作者: rapoo

Delphi中如何打开一个文件,在里面查找指定的字符串
Delphi中如何打开一个文件,在里面查找指定的字符串?

[解决办法]
assfile(f, 'a.txt ');
reset(f);
while not eof(f) do
begin
Readln(F,S);
if Pos( 'yourfindstring ',S)> 0 then
begin
showmessage( '找到了 ');
break;
end;
end;
closefile(f);
[解决办法]
var
F: TextFile;
S: string;
begin
if OpenDialog1.Execute then //如果选择文件名成功
begin
AssignFile(F, OpenDialog1.FileName);
Reset(F);
While not Eof(F) do //文件未到末尾
begin
Readln(F, S); //读一行
if Pos( 'yourfindstring ',S)> 0 then
begin
ShowMessage( '找到了 ');
break;
end;
end;
CloseFile(F);
end;
end;
-------------------------------
我的更详细版本
[解决办法]
装载到StringList中更简单.
var
str :Tstrings;
i:integer;
begin
str :=TStringList.create;
str.LoadFromFile( '文件全路径 ');
for i:=0 to str.count-1 do
begin
if pos( 'yourstring ',str.string[i])> 0 then
ShowMessage( '找到了 ');
end;

读书人网 >.NET

热点推荐