Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

String#bytesize

bytesize → integer

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
See also #bytes #byteslice #byterindex #bytesplice also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0