View source code
Display the source code in std/string.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
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 usinglocal clone.
Function std.string.stripRight
Strips trailing whitespace (as defined by isWhite
) or
as specified in the second argument.
auto stripRight(Range)(
Range str
)
if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && !isConvertibleToString!Range && isSomeChar!(ElementEncodingType!Range));
auto stripRight(Range, Char)(
Range str,
const(Char)[] chars
)
if ((isBidirectionalRange!Range && isSomeChar!(ElementEncodingType!Range) || isConvertibleToString!Range) && isSomeChar!Char);
Parameters
Name | Description |
---|---|
str | string or random access range of characters |
chars | string of characters to be stripped |
Returns
slice of str
stripped of trailing whitespace or characters
specified in the second argument.
See Also
Generic stripping on ranges: stripRight
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");
Example
assert(stripRight(" hello world ", "x") ==
" hello world ");
assert(stripRight(" hello world ", " ") ==
" hello world");
assert(stripRight(" hello worldxy ", "xy ") ==
" hello world");
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
License
Copyright © 1999-2025 by the D Language Foundation | Page generated by ddox.