Ruby | String bytesize method
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 methodputs "GeeksforGeeks".bytesizeputs "Ruby".bytesize |
Output:
13 4
Example 2:
# Ruby program to demonstrate# the bytesize method # Taking a string and# using the methodputs "String Class".bytesizeputs "Methods".bytesize |
Output:
12 7





Please Login to comment...