instance method
String#lstrip
() -> ::String
lstrip(*selectors) → new_string
string.c
View on GitHub ↗
static VALUE
rb_str_lstrip(int argc, VALUE *argv, VALUE str)
{
char *start;
long len, loffset;
RSTRING_GETMEM(str, start, len);
if (argc > 0) {
char table[TR_TABLE_SIZE];
VALUE del = 0, nodel = 0;
tr_setup_table_multi(table, &del, &nodel, str, argc, argv);
loffset = lstrip_offset_table(str, start, start+len, STR_ENC_GET(str), table, del, nodel);
}
else {
loffset = lstrip_offset(str, start, start+len, STR_ENC_GET(str));
}
if (loffset <= 0) return str_duplicate(rb_cString, str);
return rb_str_subseq(str, loffset, len - loffset);
}
Returns a copy of self with leading whitespace removed; see Whitespace in Strings:
Example
whitespace = "\x00\t\n\v\f\r " s = whitespace + 'abc' + whitespace # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r " s.lstrip # => "abc\u0000\t\n\v\f\r "
If selectors are given, removes characters of selectors from the beginning of self:
Example
s = "---abc+++" s.lstrip("-") # => "abc+++"
selectors must be valid character selectors (see Character Selectors), and may use any of its valid forms, including negation, ranges, and escapes:
Example
"01234abc56789".lstrip("0-9") # "abc56789" "01234abc56789".lstrip("0-9", "^4-6") # "4abc56789"
Related: see Converting to New String.
Ruby version changes
-
3.0
-
The following methods now return or yield
Stringinstances instead of subclass instances when called on subclass instances: [Bug #10845]
-