Count ALL characters in a string in Ruby

Is there an equivalent to PHP strlen method in Ruby?

I know about the Ruby String#count method, but this requires a character set to be counted. In my situation, I want to count ALL characters, not just certain characters.

+6
source share
1 answer

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

Returns the length of the str. character str.

Example:

 "abc 12-".size # => 7 
+11
source

Source: https://habr.com/ru/post/970004/


All Articles