红宝石 |字符串 getbyte 方法
getbyte是 Ruby 中的 String 类方法,用于将第 index 个字节作为整数返回。
Syntax: str.getbyte(index)
Parameters: Here, str is the given string.
Returns: Indexth byte as an integer.
示例 1:
# Ruby program to demonstrate
# the getbyte method
# Taking a string and
# using the method
puts "Ruby".getbyte(1)
puts "String".getbyte(4)
输出:
117
110
示例 2:
# Ruby program to demonstrate
# the getbyte method
# Taking a string and
# using the method
# it will return nil
puts "Sample".getbyte(7)
puts "Program".getbyte(4)
输出:
114