Javascript replace characters with charcodes under 32 with \x(charcode)
<p>Characters under 0x20 aren't shown, so I would like to escape them as '\x0D', for example. </p>

<p>Currently, I'm using:</p>

<pre><code>str = str.replace(/([\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f])/,function(b){
                    var b = b.charCodeAt();
                    return '\\x'+(b&lt;16?'0':'')+b.toString(16).toUpperCase();
                });
</code></pre>

<p>Is there a better way? Originally, I was doing:</p>

<pre><code>str = escape(str).replace('%(\d\d)','\\x$1');
</code></pre>

<p>..but it escaped characters with values above 32.</p>
