LeftPartR function
String / Filename routines
Return to Introduction  Previous page  Next page
Unit
acUtils  

Declaration
function LeftPartR(const SubStr, Str: String): String;  

Description
The LeftPartR function finds the LAST occurence of any sub-string (SubStr parameter) in specified string (Str parameter), and returns the part of string (SubStr) BEFORE the separator (Str). If the SubStr can not be found in the Str, the function returns empty string. Unlike LeftPart function, the LeftPartR starts searching the sub-string from the right side of string.  
 
tip If you would like to find FIRST occurence of sub-string in specified string — use LeftPart function.  

Example
ParentRegKey := RightPartR('\''Software\Microsoft\CurrentVersion');  
// the result will be 'Software\Microsoft'  

Original code
function LeftPartR(const SubStr, Str: String): String;  
var  
  I: Integer;  
begin  
  I := PosR(SubStr, Str);  
  if I <> 0 then  
    Result := Copy(Str, 1, I - 1)  
  else  
    Result := '';  
end;  

See also
LeftPart, RightPart, LeftPartR, RightPartR, PosR and SplitStr routines.