# Fast byte replacement on string

**URL:** <https://www.ruby-forum.com/t/fast-byte-replacement-on-string/161462>\
**Category:** Ruby\
**Created:** [February 26, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/fast-byte-replacement-on-string/161462 "2009-02-26T18:49:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfsog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bfsog](https://www.ruby-forum.com/u/bfsog)\
**Post date:** [February 26, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/fast-byte-replacement-on-string/161462/1 "2009-02-26T18:49:02Z")

</div>

I’m implementing a requirement for a Google service that reads in part

With urls…

“To start, repeatedly URL-unescape the URL until it has no more  
hex-encodings.”

Do lots of stuff here with url.

Finally “After performing these steps, percent-escape all characters in  
the URL which are \<= ASCII 32, \>= 127, or “%”. The escapes should use  
uppercase hex characters.”

Do any of you have a very fast way to do this?

The implementation I have now is dreadfully slow, I’ll spare you my  
solution. J

I need a solution that will work with Ruby 1.8.6 & 1.9.1

Andy
