filmnut
filmnut

Reputation: 746

Count ALL Characters in a String in Ruby

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.

Upvotes: 11

Views: 22999

Answers (1)

Arup Rakshit
Arup Rakshit

Reputation: 118261

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

Returns the character length of str.

Example :

"abc 12-".size  # => 7

Upvotes: 21

Related Questions