• Jon © (19.01.08 05:21) [0]
    How can I search within a binary string for a substring?
    Both Pos and IndexOfStr fail when a #$00 is encountered.
  • Vladimir Kladov © (19.01.08 10:53) [1]
    I'll fix IndexOfStr (IndexOfChar) in the update (soon).
  • Jon © (19.01.08 19:42) [2]
    Works perfectly in v2.86 - many thanks!
  • Jon © (20.01.08 06:16) [3]

    > Works perfectly in v2.86 - many thanks!

    Upon further testing I was wrong.

    If the substring in IndexOfStr(String,Substring) is not found, the procedure locks up.

    Also, if the substring contains #$00 such as IndexOfStr(String,#$00#$FF) the result is the position of first #$00 found.
  • Vladimir Kladov © (20.01.08 11:27) [4]
    PAS_VERSION works perfectly. Here is a fix for asm-version. When you test it, I'll release an update.

    function IndexOfStr( const S, Sub : String ) : Integer;
    asm
           PUSH     EBX
           PUSH     ESI
           PUSH     EDI

           PUSH     EAX
           MOV      EAX, EDX
           PUSH     EDX
           CALL     System.@LStrLen
           MOV      EDI, EAX
           POP      EAX
           //CALL     System.@LStrToPChar
           CALL     EAX2PChar
           MOV      BL, [EAX]
           XCHG     EAX, [ESP]
           //CALL     System.@LStrToPChar
           CALL     EAX2PChar

           MOV      ESI, EAX

           DEC      EAX
    @@1:    INC      EAX
           MOV      DL, BL
           MOV      ECX, [ESI-4]
           SUB      ECX, EAX
           ADD      ECX, ESI

           CMP      ECX, EDI
           JL       @@ret__1

           CALL     StrScanLen
           TEST     EAX, EAX
           JE       @@exit__1
           DEC      EAX

           POP      EDX
           PUSH     EDX

           MOV      ECX, EDI
           PUSH     EAX
           //CALL     StrLComp
           CALL     CompareMem
           TEST     AL, AL
           POP      EAX
           JZ       @@1

           SUB      EAX, ESI
           INC      EAX
           JMP      @@exit

    @@ret__1:
           XOR      EAX, EAX
    @@exit__1:
           DEC      EAX
    @@exit:
           POP      EDX
           POP      EDI
           POP      ESI
           POP      EBX
    end;

  • Jon © (20.01.08 15:32) [5]

    > PAS_VERSION works perfectly. Here is a fix for asm-version.
    >  When you test it, I'll release an update.


    Yes, it works. Thank you and well done!
Есть новые Нет новых   [134465   +2][b:0][p:0.002]