how to search a hex in stream Efficiently and quickly?
if the stream is big ,how to search quickly in the stream and retun the postion ?
function FindInMemStream(Stream: TMemoryStream; What: String):Integer;
var
bufBuffer, bufBuffer2: array[0..254] of Char;
i: Integer;
begin
Result := 0;
i := 0;
FillChar(bufBuffer, 255, #0);
FillChar(bufBuffer2, 255, #0);
StrPCopy(@bufBuffer2, What);
Stream.Position:=0;
while Stream.Position <> Stream.Size do
begin
Stream.Read(bufBuffer[0],Length(What));
if CompareMem(@bufBuffer,@bufBuffer2,Length(What)) then
begin
Result := Stream.Position-Length(What);
Exit;
end;
i := i + 1;
Stream.Seek(i,0)
end;
end;
i want to change the function to serch hex ,is this function Efficient? can u give me a Efficient function to serch hex ?
I have adapted the code from POS function available in system.pas 🙂
If you need to find some hex, you can use like: