红宝石 |字符串 chr 方法
chr是 Ruby 中的 String 类方法,用于返回字符串开头的单字符字符串。
Syntax:str.chr
Parameters: Here, str is the given string.
Returns: A one-character string at the beginning of the string.
示例 1:
# Ruby program to demonstrate
# the chr method
# Taking a string and
# using the method
puts "Ruby".chr
puts "Method".chr
输出:
R
M
示例 2:
# Ruby program to demonstrate
# the chr method
# Taking a string and
# using the method
puts "String".chr
puts "Class".chr
输出:
S
C