當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Ruby String bytes用法及代碼示例

bytes是Ruby中的String類方法,用於返回給定字符串的字節數組。

用法: str.bytes

參數:在這裏,str是指定的字符串。


返回值:字節數組。

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


相關用法


注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 Ruby | String bytes Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。