[英]Count ALL Characters in a String in Ruby
Is there an equivalent to PHP's strlen
method in Ruby? 在Ruby中有相当于PHP的strlen
方法吗?
I know about Ruby's String#count
method, but it requires that I define a set of characters to count. 我知道Ruby的String#count
方法,但它要求我定义一组字符来计算。 In my situation, I want to count ALL characters, not just certain characters. 在我的情况下,我想要计算所有字符,而不仅仅是某些字符。
Use String#size
or String#length
method. 使用String#size
或String#length
方法。 It will work for you. 它会对你有用。
Returns the character length of
str.
返回str.
的字符长度str.
Example : 示例:
"abc 12-".size # => 7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.