End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
String#bytesize
bytesize → integer
string.c
View on GitHub ↗
static VALUE
rb_str_bytesize(VALUE str)
{
return LONG2NUM(RSTRING_LEN(str));
}
Returns the count of bytes (not characters) in self:
Example
'foo'.bytesize # => 3 'тест'.bytesize # => 8 'こんにちは'.bytesize # => 15
Contrast with String#length:
Example
'foo'.length # => 3 'тест'.length # => 4 'こんにちは'.length # => 5