Ruby | String byteslice Method Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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 is given by the second if the two integers passed. A substring containing bytes at offsets given by the range if the range is passed. nil if the length is negative or initial offset falls outside the string or the beginning of the range is greater than the end. Note: If an offset is negative then it is counted from the end of the string. Example 1: Ruby # Ruby program to demonstrate # the byteslice method # Taking a string and # using the method puts "Ruby String".byteslice(9) puts "Methods".byteslice(2, 4) Output: n thod Example 2: Ruby # Ruby program to demonstrate # the byteslice method # Taking a string and # using the method puts "Ruby String".byteslice(-1) puts "Methods".byteslice(1..4) Output: g etho Comment More infoAdvertise with us Next Article Ruby | String byteslice 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 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 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 Like