VOOZH about

URL: https://apidock.com/ruby/String/strip

⇱ String#strip - APIdock


method

strip

ruby latest stable - Class: String
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 #=> "hello"
"\tgoodbye\r\n".strip #=> "goodbye"
"\x00\t\n\v\f\r ".strip #=> ""
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);
}

Related methods