** A method that a string has. The length method is a method that counts the number of characters in a string. Spaces between characters are also counted. ** **
The use of methods Execute by connecting the method name "length" with dot. </ Font> for the value as shown below.
[Example] irb
#Output the number of characters in the string
irb(main):001:0> "Hello World".length
=> 11
"Hello World" .length can also be viewed as a single expression. In the above example, what is displayed after => is the number of characters "11" of "Hello World". The character itself is "10" characters, but it will be "11" characters including "" spaces.
Now, let's actually try the length method.
irb
#Output the number of characters with the length method
irb(main):001:0> "good morning".length
#If it continues to be displayed like this, it is successful
=> 12
** A method is a collection of some processing in programming. The length method is a method that counts the number of characters in a character string. ⚠︎ Blanks (spaces) are also counted. ** **
Recommended Posts