Ruby Integer chr函数与示例
Ruby 中的chr函数根据编码返回包含由 int 值表示的字符的字符串。
Syntax: string.chr([encoding])
Parameter: The function takes the integer value whose encoding is to be done. It takes a non-mandatory parameter encoding if encoding is to be done according to that.
Return Value: The function returns character.
示例 #1:
# Ruby Program of Integer chr function
# Initializing the numbers
num1 = 65
num2 = 66
num3 = 97
num4 = 245
# Prints the chr
# after encoding
puts num1.chr
puts num2.chr
puts num3.chr
puts num4.chr(Encoding::UTF_8)
输出:
A
B
a
õ
示例 #2:
# Ruby Program of Integer chr function
# Initializing the numbers
num1 = 119
num2 = 68
num3 = 89
num4 = 255
# Prints the chr
# after encoding
puts num1.chr
puts num2.chr(Encoding::UTF_8)
puts num3.chr
puts num4.chr(Encoding::UTF_8)
输出:
w
D
Y
ÿ