delphi – 有没有“Pos”函数来查找字节?
发布时间:2020-12-15 09:33:19 所属栏目:大数据 来源:网络整理
导读:var FileBuff: TBytes; Pattern: TBytes;begin FileBuff := filetobytes(filename); Result := CompareMem(@Pattern[0],@FileBuff[0],Length(Pattern));end; 有没有任何功能,如 Result := Pos(@Pattern[0],@FileBuff[0]); 解决方法 我认为这样做: function
var FileBuff: TBytes; Pattern: TBytes; begin FileBuff := filetobytes(filename); Result := CompareMem(@Pattern[0],@FileBuff[0],Length(Pattern)); end; 有没有任何功能,如 Result := Pos(@Pattern[0],@FileBuff[0]); 解决方法
我认为这样做:
function BytePos(const Pattern: TBytes; const Buffer: PByte; const BufLen: cardinal): PByte; var PatternLength: cardinal; i: cardinal; j: cardinal; OK: boolean; begin result := nil; PatternLength := length(Pattern); if PatternLength > BufLen then Exit; if PatternLength = 0 then Exit(Buffer); for i := 0 to BufLen - PatternLength do if PByte(Buffer + i)^ = Pattern[0] then begin OK := true; for j := 1 to PatternLength - 1 do if PByte(Buffer + i + j)^ <> Pattern[j] then begin OK := false; break end; if OK then Exit(Buffer + i); end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |