Ruby Integer chr function with example
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:
# Ruby Program of Integer chr function # Initializing the numbers num1 = 65num2 = 66num3 = 97num4 = 245 # Prints the chr # after encoding puts num1.chrputs num2.chrputs num3.chrputs num4.chr(Encoding::UTF_8) |
Output:
A B a õ
Example #2:
# Ruby Program of Integer chr function # Initializing the numbers num1 = 119num2 = 68num3 = 89num4 = 255 # Prints the chr # after encoding puts num1.chrputs num2.chr(Encoding::UTF_8)puts num3.chrputs num4.chr(Encoding::UTF_8) |
Output:
w D Y ÿ


