End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
String#length
string.length → integer
string.c
View on GitHub ↗
VALUE
rb_str_length(VALUE str)
{
return LONG2NUM(str_strlen(str, NULL));
}
Returns the count of characters (not bytes) in self:
Example
"\x80\u3042".length # => 2 "hello".length # => 5
String#size is an alias for String#length.
Related: String#bytesize.