Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
String#size
() -> ::Integer
size
string.c
View on GitHub ↗
VALUE
rb_str_length(VALUE str)
{
return LEN2NUM(str_strlen(str, NULL));
}
Alias of #length
Returns the count of characters (not bytes) in self:
Example
'foo'.length # => 3 'こんにちは'.length # => 5
Contrast with String#bytesize:
Example
'foo'.bytesize # => 3 'こんにちは'.bytesize # => 15
Related: see Querying.