Home

rstrip

rstrip is a string processing operation found in several programming languages that removes characters from the right end of a string. The name stands for right-strip, referring to the direction of removal. The behavior is most commonly associated with removing trailing whitespace, but languages often allow a custom set of characters to be removed as well.

In its default form, rstrip removes trailing whitespace characters such as spaces, tabs, and newlines. When

Return value and mutability vary by language. In languages with immutable strings (such as Python), rstrip returns

Examples illustrate common usage: "hello world ".rstrip() yields "hello world"; "path/to/file.txt\n".rstrip() yields "path/to/file.txt". When a character

See also lstrip (left-strip) and strip (both sides). Rstrip is frequently used to clean input, remove line

an
optional
argument
is
provided,
it
is
interpreted
as
a
set
of
characters
to
remove
from
the
end
of
the
string.
The
characters
are
considered
individually;
removal
continues
as
long
as
the
last
character
belongs
to
the
specified
set.
The
method
does
not
affect
characters
at
the
left
side
or
within
the
string,
only
trailing
characters.
a
new
string
and
leaves
the
original
unchanged.
Some
languages
offer
a
destructive
in-place
variant
(often
named
rstrip!),
which
modifies
the
original
string.
set
is
supplied,
e.g.,
"abc123".rstrip("123"),
trailing
characters
in
the
set
are
removed
until
a
character
not
in
the
set
is
encountered,
producing
"abc".
terminators,
or
prepare
strings
for
parsing
and
storage.