1. Home
  2. Computing & Technology
  3. Delphi Programming

LastPos function - last occurrence of one string within another

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2004 Delphi Tips
  7. LastPos function - last occurrence of one string within another

©2009 About.com, a part of The New York Times Company.

All rights reserved.