红宝石 |字符串字节方法
bytes是 Ruby 中的 String 类方法,用于返回给定字符串的字节数组。
Syntax: str.bytes
Parameters: Here, str is the specified string.
Returns: An array of bytes.
示例 1:
# Ruby program to demonstrate
# the bytes method
# Taking a string and
# using the method
puts "String".bytes
输出:
83
116
114
105
110
103
示例 2:
# Ruby program to demonstrate
# the bytes method
# Taking a string and
# using the method
puts "ABCD".bytes
输出:
65
66
67
68