Word文件就不知道了.
文本文件可以一行行的读出来,然后判断.
Try this:
function PosInFile(Str,FileName:string):integer;
var
Buffer:array[0..1023]of char;
BufPtr,BufEnd:integer;
F:File;
Index:integer;
Increment:integer;
c:char;
function NextChar:char;
begin
if BufPtr>=BufEnd then
begin
BlockRead(F,Buffer,1024,BufEnd);
BufPtr := 0;
end;
Result := Buffer[BufPtr];
Inc(BufPtr);
end;
begin
Result := -1;
AssignFile(F,FileName);
Reset(F,1);
BufPtr:=0;
BufEnd:=0;
Index := 0;
Increment := 1;
repeat
c:=NextChar;
if c=Str[Increment] then
Inc(Increment)
else
begin
Inc(Index,Increment);
Increment := 1;
end;
if Increment=(Length(Str)+1) then
begin
Result := Index;
Break;
end;
until BufEnd = 0;
CloseFile(F);