Trim v0.1.0

Source
Returns a copy with the surrounding whitespace dropped.

Package: Text

Signature

func Trim(self) -> String;

Returns

A new String with the leading and trailing whitespace removed, in a block of its own. The receiver is left untouched.

Only the ends are trimmed — whitespace inside the string is kept. A string that is nothing but whitespace trims down to the empty string, and so does the empty string.

Whitespace is space, tab, newline, and carriage return, which is exactly what IsSpace reports.

Example

import Text::String;

func Main() -> int {
    var padded = String::From("  Hello, Rux!  \n");

    var text = padded.Trim(); // "Hello, Rux!"
    text.Length();            // 11

    text.Free();
    padded.Free();
    return 0;
}

See also

  • String — the string type
  • IsSpace — the bytes this treats as whitespace
  • Substring — drop bytes from the ends by offset instead