Skip to content

Getting Ascii value

17/12/2010

==>find ASCII value of the string character
way =1
“shanmugam”.each_byte do |ascii|
print (ascii+1).chr
end
way =2
“shanmugam”.split(”).each do |each_character|
print (each_character[0]+1).chr
end
way =3
?a – return ascii value

==>shift
it will return first value of array and delete  the value from array

EX:

irb(main):001:0> a=”hellow world”.split(”)
=> [“h”, “e”, “l”, “l”, “o”, “w”, ” “, “w”, “o”, “r”, “l”, “d”]
irb(main):002:0> a
=> [“h”, “e”, “l”, “l”, “o”, “w”, ” “, “w”, “o”, “r”, “l”, “d”]
irb(main):003:0> a.shift
=> “h”
irb(main):004:0> a
=> [“e”, “l”, “l”, “o”, “w”, ” “, “w”, “o”, “r”, “l”, “d”]
irb(main):005:0>

Advertisements

From → Ruby

Leave a Comment

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

%d bloggers like this: