Ruby | String bytesize method Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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 # 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 # Ruby program to demonstrate # the bytesize method # Taking a string and # using the method puts "String Class".bytesize puts "Methods".bytesize Output: 12 7 Comment More infoAdvertise with us Next Article Ruby | String bytesize method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads Ruby | String byteslice Method byteslice is a String class method in Ruby which is used for the byte reference. Syntax: str.byteslice Parameters: Here, str is the specified string. Returns: A substring of one byte at that position if only a single integer passed. A substring starting at the offset given by the first, and a length 1 min read Ruby | String bytes Method bytes is a String class method in Ruby which is used to return an array of the bytes for the given string. Syntax: str.bytes Parameters: Here, str is the specified string. Returns: An array of bytes. Example 1: Ruby # Ruby program to demonstrate # the bytes method # Taking a string and # using the m 1 min read Ruby | String each_byte Method each_byte is a String class method in Ruby which is used to passes each byte in the given string to the given block or returns an enumerator if no block is given. Syntax: str.each_byte {|integer| block } Parameters: Here, str is the given string. Returns: An enumerator. Example 1: Ruby # Ruby progra 1 min read Ruby | String getbyte Method getbyte is a String class method in Ruby which is used to return the indexth byte as an integer. Syntax: str.getbyte(index) Parameters: Here, str is the given string. Returns: Indexth byte as an integer. Example 1: Ruby # Ruby program to demonstrate # the getbyte method # Taking a string and # using 1 min read Ruby | String crypt Method crypt is a String class method in Ruby which is used to returns the string generated by calling crypt(3) standard library function with str and salt_str. Syntax: crypt(salt_str)-> new_str Parameters: Here, str is the given string and salt_str is the specified salt for crypt method. Example 1: Rub 1 min read Ruby | String hex Method hex is a String class method in Ruby which is used to treats the leading characters from the given string as a string of hexadecimal digits (with an optional sign and an optional 0x) and returns the corresponding number. Zero is returned on error. Syntax: str.hex Parameters: Here, str is the given s 1 min read Ruby | String capitalize() Method capitalize is a String class method in Ruby which is used to return a copy of the given string by converting its first character uppercase and the remaining to lowercase. Syntax: str.capitalize Parameters: Here, str is the given string which is to be converted. Returns: Copy of the string with the f 1 min read Ruby | String capitalize! Method capitalize! is a String class method in Ruby which is used to return a copy of the given string by converting its first character uppercase and the remaining to lowercase. The only difference between capitalize and capitalize! method is that capitalize! method will return nil if no changes are made. 1 min read Ruby | String delete() Method delete is a String class method in Ruby which is used to return a copy of the given string with all characters in the intersection of its arguments deleted. Syntax: str.delete(parameter_list) Parameters: Here, str is the given string and parameter_list are the specified characters. Returns: A new co 1 min read Ruby | String insert Method insert is a String class method in Ruby which is used to inserts the specified string before the character at the given index, modifying the given one. Negative indices count from the end of the string, and insert after the given character. Syntax: str.insert(index, other_str) Parameters: Here, str 1 min read Like