红宝石 |字符串代码点方法
codepoints是 Ruby 中的 String 类方法,用于返回 str 中字符的整数序数数组。
Syntax: str.codepoints
Parameters: Here, str is the given string.
Returns: An array of the Integer ordinals of the characters in str.
示例 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