smlabc 正解``只是要注意字符分割处, 如// 返回 第一次查找到 ASubStr 子符所在文件流位置, 没找到返回 0function FindStr(const AFileName: string; const ASubStr: string; const AStartSearchPos: Int64 = 1): Int64;const ReadBlockSize: Integer = 1024;var iSubStrLen: Integer; n: Integer; FileStream: TFileStream; Buffer: string; // array of Char; iLeaveSize: Int64; iBufferLen: Integer; iPos: Integer;begin Result := 0; iSubStrLen := Length(ASubStr); n := iSubStrLen div ReadBlockSize + 1; // ReadBlockSize * n 保证 > iSubStrLen FileStream := TFileStream.Create(AFileName, fmShareDenyWrite); try FileStream.Position := AStartSearchPos; iLeaveSize := FileStream.Size - FileStream.Position; while iLeaveSize >= iSubStrLen do begin iBufferLen := ReadBlockSize * n; if iBufferLen > iLeaveSize then iBufferLen := iLeaveSize; SetLength(Buffer, iBufferLen); // 读取 iBufferLen 大小到 Buffer if FileStream.Read(Buffer, iBufferLen) < iSubStrLen then Break;// if StrPos(PChar(Buffer), PChar(@ASubStr[1])) <> nil then iPos := Pos(ASubStr, Buffer); if iPos > 0 then begin Result := FileStream.Position + iPos; Break; end else begin // 回退 子串长度减一位 FileStream.Position := FileStream.Position - (iSubStrLen -1); end; iLeaveSize := FileStream.Size - FileStream.Position; end; finally FileStream.Free; end;end;// 没有验证``