Count ALL Characters in a String in Ruby

count, ruby, string

Solution

Use `String#size` or `String#length` method. It will work for you.

Returns the character length of `str.`

Example :

"abc 12-".size  # => 7

Problem

Is there an equivalent to PHP's `strlen` method in Ruby? I know about Ruby's `String#count` method, but it requires that I define a set of characters to count. In my situation, I want to count ALL characters, not just certain characters.

Original source