Todd Benson
9/13/2008 12:21:00 AM
On Fri, Sep 12, 2008 at 6:40 PM, James Gray <james@grayproductions.net> wrote:
> On Sep 12, 2008, at 5:25 PM, Nick Bo wrote:
>
>> my issue is I dont know how to take the character
>> and convert it into ASCII.
>
> In Ruby 1.8 you can just index into the String and Ruby will return the
> character value:
>
>>> "a"[0]
> => 97
>
> Hope that helps and welcome to Ruby!
Also, if you are required to iterate, you can do String#each_byte
after an Array#join, but I don't think that's what you are looking
for, but I couldn't resist (I know I'm a clown)...
[('a'..'z'),('A'..'Z'),('0'..'9')].inject([]){|s,i|s+i.map}.join.each_byte{|b|p
b}
If you need to do an each/do, you should probably do as James suggests.
Todd