开发者

Need help in trying to convert number into character code

开发者 https://www.devze.com 2023-04-08 02:15 出处:网络
I am using irb/ruby1.9.1/windows7. I need to convert the letter \"M\" into character code. I wrote the code below:

I am using irb/ruby1.9.1/windows7.

I need to convert the letter "M" into character code. I wrote the code below:

>M

I expected the result to be 77. But the result was "M".

How can I make the letter into chara开发者_开发百科cter code?


Why not use ord

"M".ord #=> 77


Try method ord

'M'.ord

in order to get the character code.

0

精彩评论

暂无评论...
验证码 换一张
取 消