# Escape character with decimal value

**URL:** <https://www.ruby-forum.com/t/escape-character-with-decimal-value/189617>\
**Category:** Ruby\
**Created:** [June 4, 2010, 1:08am UTC](https://www.ruby-forum.com/t/escape-character-with-decimal-value/189617 "2010-06-04T01:08:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [June 4, 2010, 1:08am UTC](https://www.ruby-forum.com/t/escape-character-with-decimal-value/189617/1 "2010-06-04T01:08:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [June 4, 2010, 12:55pm UTC](https://www.ruby-forum.com/t/escape-character-with-decimal-value/189617/2 "2010-06-04T12:55:50Z")

</div>

2010/6/4 Roger P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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
