Getting an ASCII character code in Ruby using `?` (question mark) fails

后端 未结 6 1006
旧时难觅i
旧时难觅i 2020-12-08 06:01

I\'m in a situation where I need the ASCII value of a character (for Project Euler question #22, if you want to get specific) and I\'m running into an issue.

Being n

6条回答
  •  广开言路
    2020-12-08 06:57

    Ruby Programming/ASCII

    In previous ruby version before 1.9, you can use question-mark syntax.

    ?a
    

    After 1.9, we use ord instead.

    'a'.ord    
    

提交回复
热议问题