gpt4 book ai didi

delphi - 有没有 "Pos"函数来查找字节?

转载 作者:行者123 更新时间:2023-12-03 15:08:42 28 4
gpt4 key购买 nike

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;

关于delphi - 有没有 "Pos"函数来查找字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4959566/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com