From: Roger Pack on
I'm familiar with
"\xnn" to escape a hex value in a string.

Is there any way to escape a character with a decimal value?
"#{197.chr}"
works but doesn't seem like an escape per se...
Thanks.
-r
--
Posted via http://www.ruby-forum.com/.

From: Robert Klemme on
2010/6/4 Roger Pack <rogerpack2005(a)gmail.com>:
> I'm familiar with
> "\xnn" to escape a hex value in a string.
>
> Is there any way to escape a character with a decimal value?
> "#{197.chr}"
> works but doesn't seem like an escape per se...

There is octal

irb(main):008:0> "\011"
=> "\t"

But not decimal AFAIK. You would have to do the unescaping yourself, e.g.

irb(main):018:0> s = '\\33'
=> "\\33"
irb(main):019:0> s.gsub(/\\([1-9]\d*)/){ $1.to_i.chr }
=> "!"

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/