strip()
public
Returns a copy of str with leading and trailing whitespace
removed.
Whitespace is defined as any of the following characters: null, horizontal
tab, line feed, vertical tab, form feed, carriage return, space.
" hello ".strip
"\tgoodbye\r\n".strip
"\x00\t\n\v\f\r ".strip
Show source
static VALUE
rb_str_strip(VALUE str)
{
char *start;
long olen, loffset, roffset;
rb_encoding *enc = STR_ENC_GET(str);
RSTRING_GETMEM(str, start, olen);
loffset = lstrip_offset(str, start, start+olen, enc);
roffset = rstrip_offset(str, start+loffset, start+olen, enc);
if (loffset <= 0 && roffset <= 0) return rb_str_dup(str);
return rb_str_subseq(str, loffset, olen-loffset-roffset);
}