📜  红宝石 |字符串 getbyte 方法

📅  最后修改于: 2022-05-13 01:54:45.099000             🧑  作者: Mango

红宝石 |字符串 getbyte 方法

getbyte是 Ruby 中的 String 类方法,用于将第 index 个字节作为整数返回。

示例 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