Ruby | StringIO bytes function Last Updated : 26 Dec, 2022 Comments Improve Suggest changes Like Article Like Report StringIO#bytes() : bytes() is a StringIO class method which returns the value of bytes of the stringIO. Syntax: StringIO.bytes() Parameter: StringIO values Return: value of bytes of the stringIO. Example #1 : Ruby # Ruby code for StringIO.bytes() method # loading StringIO require 'stringio' # declaring StringIO a = StringIO.new("geeksforgeeks") # StringIO puts "StringIO a : #{a.string}\n\n" # bytes form puts "StringIO a bytes form : #{a.bytes}\n\n" Output : StringIO a : geeksforgeeks StringIO a bytes form : # Example #2 : Ruby # Ruby code for StringIO.bytes() method # loading StringIO require 'stringio' # declaring StringIO a = StringIO.new("icancode") # StringIO puts "StringIO a : #{a.string}\n\n" # bytes form puts "StringIO a bytes form : #{a.bytes}\n\n" Output : StringIO a : icancode StringIO a bytes form : # Note : The Enumerator value can change as per the compiler and system. Comment More infoAdvertise with us Next Article Ruby | StringIO bytes function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads Ruby | StringScanner get_byte function StringScanner#get_byte() : get_byte() is a StringScanner class method which returns the byte of pointer on the StringScanner. Syntax: StringScanner.get_byte() Parameter: StringScanner values Return: the byte of pointer on the StringScanner. Example #1 : Ruby # Ruby code for StringScanner.get_byte() 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 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 | StringScanner check function StringScanner#check() : check() is a StringScanner class method which returns the value that scan would return, without advancing the scan pointer Syntax: StringScanner.check() Parameter: StringScanner values Return: the value that scan would return, without advancing the scan pointer Example #1 : R 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 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 | Random bytes() function Random#bytes() is a Random class method which returns random binary string containing size bytes. Syntax: Random.bytes() Parameter: Random values Return: random binary string containing size bytes. Example #1 : Ruby # Ruby code for Random.bytes() method # declaring Random value date_a = Random.new() 1 min read Ruby | StringScanner charpos function StringScanner#charpos() : charpos() is a StringScanner class method which returns the character position of the scan pointer. Syntax: StringScanner.charpos() Parameter: StringScanner values Return: the character position of the scan pointer Example #1 : Ruby # Ruby code for StringIO.charpos() method 1 min read Ruby | StringScanner pos= function StringScanner#pos=() : pos=() is a StringScanner class method which sets the byte position of the scan pointer. Syntax: StringScanner.pos=() Parameter: StringScanner values Return: sets the byte position of the scan pointer. Example #1 : Ruby # Ruby code for StringScanner.pos=() method # loading Str 1 min read Like