Skip to content
Related Articles

Related Articles

Ruby | String bytesize method
  • Last Updated : 07 Jan, 2020

bytesize is a String class method in Ruby which is used to get the length of the given string in bytes.

Syntax: str.bytesize

Parameters: Here, str is the given string.

Returns: This method returns the length of the str in bytes.

Example 1:






    
# Ruby program to demonstrate
# the bytesize method
     
# Taking a string and
# using the method
puts "GeeksforGeeks".bytesize
puts "Ruby".bytesize

Output:

13
4

Example 2:




# Ruby program to demonstrate
# the bytesize method
     
# Taking a string and
# using the method
puts "String Class".bytesize
puts "Methods".bytesize

Output:

12
7

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :