length is a String class method in Ruby which is used to find the character length of the given 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.
Example 1:
puts "GFG" .length
puts "geeksforgeeks" .length
|
Output:
3
13
Example 2:
puts "g4g" .length
puts "ruby string" .length
|
Output:
3
11
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
08 Jan, 2020
Like Article
Save Article