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 program to demonstrate # the bytes method # Taking a string and # using the method puts "String".bytes |
chevron_right
filter_none
Output:
83 116 114 105 110 103
Example 2:
# Ruby program to demonstrate # the bytes method # Taking a string and # using the method puts "ABCD".bytes |
chevron_right
filter_none
Output:
65 66 67 68
Recommended Posts:
- Ruby | StringIO bytes function
- Ruby | Random bytes() function
- Ruby | String << Method
- Ruby | String == method
- Ruby | String <=> Method
- Ruby | String hex Method
- Ruby | String chr Method
- Ruby | String === Method
- Ruby | String =~ Method
- Ruby | String + Method
- Ruby | String eql? Method
- Ruby | String * Method
- Ruby | String delete() Method
- Ruby | String delete! Method
- Ruby | String chop Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



