Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

Integer value of a character in ruby?

I am looking to turn the character 'a' into 97 in ruby 1.9.2

Ruby 1.8.7

irb(main):001:0> ?a
=> 97

Ruby 1.9.2

irb(main):001:0> ?a
=> "a"
question from:https://stackoverflow.com/questions/4111283/integer-value-of-a-character-in-ruby

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You probably want String#ord:

% irb
ruby-1.9.2-head > 'a'.ord
 => 97 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...