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

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

Description
The LeftPart function finds the first occurence of any sub-string (SubStr parameter) in specified string (Str parameter) and returns the part of string (SubStr) AFTER the separator (Str). If the SubStr can not be found in the Str, the function returns empty string.  
 
tip If you would like to find LAST occurence of sub-string in specified string — use RightPartR function.  

Example
// For example, we need to get the REALM NAME (between doublequotes)  
RealmName := 'Basic realm="REALM NAME"';  
 
// let's try...  
RealmName := RightPart('="', RealmName); // result: REALM NAME"  
// and get rid from next doublequote  
RealmName := LeftPart('"', RealmName);   // result: REALM NAME  

Original code
function RightPart(const SubStr, Str: String): String;  
var  
  I: Integer;  
begin  
  I := Pos(SubStr, Str);  
  if I <> 0 then  
    Result := Copy(Str, I + Length(SubStr), Length(Str))    
  else  
    Result := '';  
end;  

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