红宝石 |字符串长度方法
length是 Ruby 中的 String 类方法,用于查找给定字符串的字符长度。
Syntax: str.length
Parameters: Here, str is the string whose length is to be calculated
Returns:It will return the character length of the str.
示例 1:
# Ruby program to demonstrate
# the length method
# Taking a string and
# using the method
puts "GFG".length
puts "geeksforgeeks".length
输出:
3
13
示例 2:
# Ruby program to demonstrate
# the length method
# Taking a string and
# using the method
puts "g4g".length
puts "ruby string".length
输出:
3
11