Ruby 字符串 codepoints 方法
codepoints 是Ruby中的一个字符串类方法,用于返回str中字符的整数序数的阵列。
语法: str.codepoints
参数: 这里,str是给定的字符串。
返回: str.codepoints是字符串类方法,用于返回str.codepoints中字符的整数位数组。
例子 1 :
# Ruby program to demonstrate
# the codepoints method
# Taking a string and
# using the method
puts "Ruby".codepoints
输出
82
117
98
121
例2 :
# Ruby program to demonstrate
# the codepoints method
# Taking a string and
# using the method
puts "String".codepoints
输出
83
116
114
105
110
103