Ruby Integer chr function with example
Last Updated :
07 Jan, 2020
The chr function in Ruby returns the string containing the character represented by the int’s value according to encoding.
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.
Example #1:
num1 = 65
num2 = 66
num3 = 97
num4 = 245
puts num1.chr
puts num2.chr
puts num3.chr
puts num4.chr(Encoding:: UTF_8 )
|
Output:
A
B
a
õ
Example #2:
num1 = 119
num2 = 68
num3 = 89
num4 = 255
puts num1.chr
puts num2.chr(Encoding:: UTF_8 )
puts num3.chr
puts num4.chr(Encoding:: UTF_8 )
|
Output:
w
D
Y
ÿ
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...