Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
String#bytesize
() -> ::Integer
bytesize → integer
string.c
View on GitHub ↗
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