strip

Strips both leading and trailing whitespace (as defined by std.uni.isWhite) or as specified in the second argument.

  1. auto strip(Range str)
  2. auto strip(Range str, const(Char)[] chars)
    strip
    (
    Range
    Char
    )
    (
    Range str
    ,
    const(Char)[] chars
    )
  3. auto strip(Range str, const(Char)[] leftChars, const(Char)[] rightChars)

Parameters

str Range

string or random access range of characters

chars const(Char)[]

string of characters to be stripped

Return Value

Type: auto

slice of str stripped of leading and trailing whitespace or characters as specified in the second argument.

Examples

assert(strip("     hello world     ", "x") ==
       "     hello world     ");
assert(strip("     hello world     ", " ") ==
       "hello world");
assert(strip("   xyxyhello worldxyxy     ", "xy ") ==
       "hello world");
assert(strip("\u2020hello\u2020"w, "\u2020"w) == "hello"w);
assert(strip("\U00010001hello\U00010001"d, "\U00010001"d) == "hello"d);
assert(strip(" hello ", "") == " hello ");
assert(strip("xxhelloyy", "x", "y") == "hello");
assert(strip("   xyxyhello worldxyxyzz    ", "xy ", "xyz ") ==
       "hello world");
assert(strip("\u2020hello\u2028"w, "\u2020"w, "\u2028"w) == "hello"w);
assert(strip("\U00010001hello\U00010002"d, "\U00010001"d, "\U00010002"d) ==
       "hello"d);
assert(strip(" hello ", "", "") == " hello ");

See Also

Generic stripping on ranges: std.algorithm.mutation._strip

Meta