From: Gianfranco Bozzetti Date: 2010-05-16T00:22:10+09:00 Subject: Re: Converting hexadecimal string to character Michael Jackson wrote: > If I have a string that represents some character in hex, what is the > easiest way to convert it to that character? For example, if I have > the string "41" how do I convert it to "\x41" (or "A")? I've been > toying around with eval and sprintf, but can't seem to get it right. > Right now I'm using the brute force approach below, but I think there > must be a better way. > > c = "41" > eval("\"\\x#{c}\"") c="41" puts c.hex.chr # prints A HTH gfb -- Posted via http://www.ruby-forum.com/.