function PosEx(const SubStr,S:AnsiString;const Offset:Cardinal=1):Integer; var iPos: Integer; i, j,LenS,LenSub: Integer; PCharS, PCharSub: PChar; begin Result := 0; LenS:=Length(S); lenSub := length(Substr); if (LenS=0) Or (lenSub=0) then Exit; if (LenS-lenSub) PCharS := PChar(s); PCharSub := PChar(Substr);
for I := Offset-1 to LenS-1 do begin if lens-Ifor j := 0 to lenSub - 1 do if PCharS[i + j] <> PCharSub[j] then break else if J=LenSub-1 then begin Result:=I+1; Exit; end; end; end;
function PosRightEx(const SubStr,S:AnsiString;const Offset:Cardinal=MaxInt):Integer; var iPos: Integer; i, j,Len,LenS,LenSub: Integer; PCharS, PCharSub: PChar; begin Result := 0; LenS:=Length(S); lenSub := length(Substr); if (LenS=0) Or (lenSub=0) then Exit; if Offset PCharS := PChar(s); PCharSub := PChar(Substr);
Len:=Offset; if Len>LenS then Len:=LenS;
for I := Len-1 downto 0 do begin if Ifor j := lenSub - 1 downto 0 do if PCharS[i -lenSub+j+1] <> PCharSub[j] then break else if J=0 then begin Result:=I-lenSub+2; Exit; end; end; end;