View source code
Display the source code in std/string.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla 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 using
local clone.
Function std.string.strip
Strips both leading and trailing whitespace (as defined by
isWhite
) or as specified in the second argument.
auto strip(Range)
(
Range str
)
if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && !isConvertibleToString!Range && isSomeChar!(ElementEncodingType!Range));
auto strip(Range, Char)
(
Range str,
const(Char)[] chars
)
if ((isBidirectionalRange!Range && isSomeChar!(ElementEncodingType!Range) || isConvertibleToString!Range) && isSomeChar!Char);
auto strip(Range, Char)
(
Range str,
const(Char)[] leftChars,
const(Char)[] rightChars
)
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 |
leftChars | string of leading characters to be stripped |
rightChars | string of trailing characters to be stripped |
Returns
slice of str
stripped of leading and trailing whitespace
or characters as specified in the second argument.
See Also
Generic stripping on ranges: strip
Example
import std .uni : lineSep, paraSep;
assert(strip(" hello world ") ==
"hello world");
assert(strip("\n\t\v\rhello world\n\t\v\r") ==
"hello world");
assert(strip("hello world") ==
"hello world");
assert(strip([lineSep] ~ "hello world" ~ [lineSep]) ==
"hello world");
assert(strip([paraSep] ~ "hello world" ~ [paraSep]) ==
"hello world");
Example
assert(strip(" hello world ", "x") ==
" hello world ");
assert(strip(" hello world ", " ") ==
"hello world");
assert(strip(" xyxyhello worldxyxy ", "xy ") ==
"hello world");
writeln(strip("\u2020hello\u2020"w, "\u2020"w)); // "hello"w
writeln(strip("\U00010001hello\U00010001"d, "\U00010001"d)); // "hello"d
writeln(strip(" hello ", "")); // " hello "
Example
writeln(strip("xxhelloyy", "x", "y")); // "hello"
assert(strip(" xyxyhello worldxyxyzz ", "xy ", "xyz ") ==
"hello world");
writeln(strip("\u2020hello\u2028"w, "\u2020"w, "\u2028"w)); // "hello"w
assert(strip("\U00010001hello\U00010002"d, "\U00010001"d, "\U00010002"d) ==
"hello"d);
writeln(strip(" hello ", "", "")); // " hello "
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.