Is there any Delphi D2010 function like PosEx that finds a sub-string inside a string starting from the end of the string?
I'm removing all the calls to the FastStrings library and one of the functions I was using was FastPosBack:
function FastPosBack(const aSourceString, aFindString : AnsiString; const aSourceLen, aFindLen, StartPos : Integer) : Integer;
I found LastDelimiter but it's not quite the same thing since it only finds the last delimiter and I can't specify a start position.
Update: Following DR comment, I've created this function:
function FastPosBack(const aSourceString, aFindString : String; const aSourceLen, aFindLen, StartPos : Integer) : Integer;
var
RevSourceString, RevFindString: string;
begin
RevSourceString := AnsiReverseString(aSourceString);
RevFindString := AnsiReverseString(aFindString);
Result := Length(aSourceString) - PosEx(RevFindString, RevSourceString, StartPos) + 1;
end;
Is there any more effective way of doing this? On a 1000000 loop cycle, Pos takes 47ms while FastPosBack takes 234ms to complete.