Technology Programming

Essential Tips for Programming in Delphi (261- 264)

Here's an "extension" function for the RTL Pos function. The LastPos returns an integer specifying the position of the LAST occurrence of one string within another.

~~~~~~~~~~~~~~~~~~~~~~~~~
function LastPos(const SubStr: String; const S: String): Integer;
begin
   result := Pos(Reverse(SubStr), Reverse(S)) ;

   if (result <> 0) then
     result := ((Length(S) - Length(SubStr)) + 1) - result + 1;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Setting up application wide hot key (keyboard short cut)
« How to encrypt a string in Delphi for .NET



Leave a reply