Quirrel4.41.0

types.String.strip

Method on every string
string.strip(): any

Returns str with white space removed from both ends.

Return value

A new string with the leading and trailing white space removed. See string.strip for which bytes count as white space and what happens to an all-white-space or empty str.

Notes

Takes no arguments. This method and string.strip call the same C++ implementation with the same behavior; " hi ".strip() gives the same result as strip(" hi "). They differ only in how the VM's introspection describes them: the module function is registered with pure fastcall in its declaration string, while this method is registered through a type-mask table that carries neither attribute, so its badges are empty even though the underlying computation is also pure.

Example

examples/types/string/strip.nut
println("\"  hi  \".strip() =", $"[{"  hi  ".strip()}]")

// same implementation as the string module function, just called as a method.
let strmod = require("string")
println("\"  hi  \".strip() == strmod.strip(\"  hi  \") =", "  hi  ".strip() == strmod.strip("  hi  "))
Output:
"  hi  ".strip() = [hi]
"  hi  ".strip() == strmod.strip("  hi  ") = true

See also

lstripReturns str with white space removed from the beginning only.
rstripReturns str with white space removed from the end only.
stripReturns str with white-space characters removed from both ends.
stringclass index