On Wed, Aug 20, 2003 at 11:46:42AM +0100, Tim Rowe wrote:
> Sorry, I wasn't completely clear.  In my problem the character I want
> to find the code for is (has to be!) in a variable.
> 
> foo = "f"
> puts foo[0]
> 
> works at the moment, but may not continue to do so.

Ah, I misunderstood.  Apologies.  

I imagine that unpack will continue to work:

	irb(main):042:0> foo = 'f'
	=> "f"
	irb(main):043:0> foo.unpack('C')[0]
	=> 102

You can also use it to get the entire string as an array of character codes
in one fell swoop:

	irb(main):045:0* foo = 'foo'
	=> "foo"
	irb(main):046:0> foo.unpack('C*')
	=> [102, 111, 111]

There may be a better way of which I'm unaware.  Actually, even if
there isn't a better way at the moment, there probably will be at some
point before foo[0] stops working. :)

-Mark