filmnut filmnut - 3 years ago 160
Ruby Question

Count ALL Characters in a String in Ruby

Is there an equivalent to PHP's

method in Ruby?

I know about Ruby's
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.

Answer Source

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

Returns the character length of str.

Example :

"abc 12-".size  # => 7
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download