Ray's playground

 

Recipe 1.6. Converting Between Characters and Values

To see the ASCII code for a specific character as an integer, use the ? operator:

1puts ?a

Output: 97

To see the integer value of a particular in a string, access it as though it were an element of an array:

1puts 'bad'[2]

Output: 100

To see the ASCII character corresponding to a given number, call its #chr method. This returns a string containing only one character:

1 puts 98.chr

Output: b

 

posted on 2009-11-04 12:49  Ray Z  阅读(179)  评论(0)    收藏  举报

导航