In this tutorial, we will learn how to get the length of a string in Ruby.
The length of a string means the total number of characters present in a given string.
To get the length of a string, we can use the built-in
length method in Ruby.
lengthmethod returns the number of characters in a string in integer format.
Here is an example, that gets the length of a
name = "prince" length = name.length puts length
Similarly, we can also use the
size method in ruby.
name = "prince" length = name.size puts length