escape character with decimal value

R

Roger Pack

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
 
R

Robert Klemme

2010/6/4 Roger Pack said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top