Ruby – Get ASCII value

Example 1:

puts ?r  #=> 114

puts ?a #=> 97

Example 2:

output=”raveendran”

puts output[0]  #=>114 ‘value of r’

puts output[1] #=> 97  ‘value of a’

Example 3:

output=”raveendran”
output.each_byte do |a|
puts a
end

>ruby ascii_from_ruby.rb
114
97
118
101
101
110
100
114
97
110
>Exit code: 0


 

Advertisements

2 thoughts on “Ruby – Get ASCII value

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s