View source code Display the source code in std/string.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.string.stripRight

Strips trailing whitespace (as defined by std.uni.isWhite).

Prototype

auto stripRight(Range)(
  Range str
)
if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && isSomeChar!(ElementEncodingType!Range));

Parameters

NameDescription
str string or random access range of characters

Returns

slice of str stripped of trailing whitespace.

Example

import std.uni : lineSep, paraSep;
assert(stripRight("     hello world     ") ==
       "     hello world");
assert(stripRight("\n\t\v\rhello world\n\t\v\r") ==
       "\n\t\v\rhello world");
assert(stripRight("hello world") ==
       "hello world");
assert(stripRight([lineSep] ~ "hello world" ~ lineSep) ==
       [lineSep] ~ "hello world");
assert(stripRight([paraSep] ~ "hello world" ~ paraSep) ==
       [paraSep] ~ "hello world");

Authors

Walter Bright, Andrei Alexandrescu, and Jonathan M Davis

License

Boost License 1.0.

Comments