Ruby | String bytes Method Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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 method puts "String".bytes Output: 83 116 114 105 110 103 Example 2: Ruby # Ruby program to demonstrate # the bytes method # Taking a string and # using the method puts "ABCD".bytes Output: 65 66 67 68 Comment More infoAdvertise with us Next Article Ruby | String bytes Method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads 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 # Ruby program to demonstrate # the bytesize method # T 1 min read 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 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 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 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 Like