# Gsub fail

**URL:** <https://www.ruby-forum.com/t/gsub-fail/183941>\
**Category:** Rails\
**Created:** [February 22, 2010, 9:02pm UTC](https://www.ruby-forum.com/t/gsub-fail/183941 "2010-02-22T21:02:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kampers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/54ee81/32.png) [@kampers](https://www.ruby-forum.com/u/kampers)\
**Post date:** [February 22, 2010, 9:02pm UTC](https://www.ruby-forum.com/t/gsub-fail/183941/1 "2010-02-22T21:02:11Z")

</div>

Hi guys: I’m trying go through a table, read a field, escape out all the  
single quotes in there, and write it back again. For some reason my  
gsub, even though by all accounts looks right, doesn’t seem to be  
working. Here is my code:

…  
y.text.gsub("’","\\’")  
thesql = “text = '”+y.text+"’"  
Capture.update\_all( thesql, "id = "+y.id.to\_s )  
…

Constantly breaks on an entry that includes  
“It’s going up on…”

right at the ’ in It’s.

Any ideas? I even wrote a loop to recurse through the string and make  
sure that I was a really a single quote (39)

Thanks…Chris

---

<div class="post-metadata">

**Author:** ![kampers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/54ee81/32.png) [@kampers](https://www.ruby-forum.com/u/kampers)\
**Post date:** [February 22, 2010, 9:39pm UTC](https://www.ruby-forum.com/t/gsub-fail/183941/2 "2010-02-22T21:39:59Z")

</div>

> y.text.gsub("’","\\’")  
> Nothing is changing here. You need to add a bang.

---

<div class="post-metadata">

**Author:** ![kampers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/54ee81/32.png) [@kampers](https://www.ruby-forum.com/u/kampers)\
**Post date:** [February 22, 2010, 10:37pm UTC](https://www.ruby-forum.com/t/gsub-fail/183941/3 "2010-02-22T22:37:57Z")

</div>

Sharagoz – wrote:

> > y.text.gsub("’","\\’")  
> > Nothing is changing here. You need to add a bang.

Doh! Thanks. I was using the same code elsewhere but without the bang.
