DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

LastChar

Returns the last character of the given string. It is an error if the string is empty.

function LastChar(const S: string): Char;
begin
  Result := S[Length(S)];
end;

StripLastChar

Removes the last character from the string S and returns the resulting string. If S is empty then it is returned unchanged.

procedure StripLastChar(var S: string);
begin
  if Length(S) > 0 then
    Delete(S, Length(S), 1);
end;

View the whole database.

Go to the DelphiDabbler website.