Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Pascal

Idiom #47 Extract string suffix

Create string t consisting in the 5 last characters of string s.
Make sure that multibyte characters are properly handled.

The end of the string s
Function RightStr(const AText: AnsiString; const ACount: Integer): AnsiString;
var j,l:integer;
begin
  l:=length(atext);
  j:=ACount;
  if j>l then j:=l;
  Result:=Copy(AText,l-j+1,j);
end;

Function RightStr() is part of the StrUtils unit that comes with FreePascal.
(let [t (clojure.string/join (take-last 5 s))])

New implementation...