End of Life Ruby 3.1 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 in self:
Example
"\x80\u3042".bytesize # => 4 "hello".bytesize # => 5
Related: String#length.