Einzelnen Beitrag anzeigen

cdkiller

Registriert seit: 23. Jul 2004
23 Beiträge
 
#5

Re: find hex codes in files

  Alt 24. Jul 2004, 13:20
ok thanks.

but this is not all. i have more problems with the function which should find these strings.

first i have convert the hex bytes into the char format whith the code at the top.

now i have also strings to search like this:

AddD 4.84

and

AddD 4.83

so my dearch function:
Delphi-Quellcode:
function FindInFile(const FileName : string;
                    SearchWord : string; MatchCase : Boolean) : Integer;
var
  fs : TFileStream;
  Buffer : array [1..10000] of Char;
  Size : Integer;
  idx : Integer;
  i : Integer;
begin
  Result := -1;
  idx := 1;
  if not MatchCase then
   SearchWord := UpperCase(SearchWord);
  fs := TFileStream.Create(FileName, fmopenreadwrite or fmsharedenynone);
  try
    Repeat
      Application.ProcessMessages;
      Size := (Fs.Size - Fs.Position);
      if Size > 10000 then Size := 10000;
      Fs.ReadBuffer(Buffer, Size);
      if not MatchCase then
      begin
        for i := 1 to Size do
          Buffer[i] := Uppercase(Buffer)[i];
      end;
      for i := 1 to Size do
      begin
        if (Buffer[i] = SearchWord[idx]) then
          Inc(idx)
        else
          idx := 1;
        if (idx = Length(SearchWord)) then
        begin
          Result := (fs.Position - Size) + i - idx + 1;
          Exit;
        end;
      end;
    until fs.Position >= fs.Size;
  finally
   fs.Free;
  end;
end;
when i start the search it should first search the 4.84 instances and when it doesn't exists it should search after 4.83. The problem is, that the function stop if they had found the 4 of 4.84 or 4.83 and they they things that is 4.84 and they do not search after 4.83

what is the problem in my code ? it must detect exactly the 4.84 or 4.83.

thanks
  Mit Zitat antworten Zitat