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:
# Ruby program to demonstrate # the length method # Taking a string and # using the method puts "GFG".length
puts "geeksforgeeks".length
|
Output:
3 13
Example 2:
# Ruby program to demonstrate # the length method # Taking a string and # using the method puts "g4g".length
puts "ruby string".length
|
Output:
3 11
Recommended Posts:
- Ruby | Hash length() method
- Ruby | Struct length() function
- Ruby | SizedQueue length() function
- Ruby | Queue length() function
- Ruby | Set length() function
- Ruby | Symbol length function
- Ruby | Array length() function
- Ruby | String inspect Method
- Ruby | String hex Method
- Ruby | String include? Method
- Ruby | String delete_suffix! Method
- Ruby | String dump Method
- Ruby | String each_byte Method
- Ruby | String * Method
- Ruby | String + Method
- Ruby | String << Method
- Ruby | String insert Method
- Ruby | String chomp! Method
- Ruby | String chop! Method
- Ruby | String chop Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

