types.String.strip
Method on every
stringReturns 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
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 ") = trueSee also
lstrip | Returns str with white space removed from the beginning only. |
rstrip | Returns str with white space removed from the end only. |
strip | Returns str with white-space characters removed from both ends. |
| string | class index |