From: Brian Candler Date: 2011-01-24T18:29:03+09:00 Subject: Re: String replace ' for mySQL insert Roland Klein overmeer wrote in post #977069: > I'm a newbie, just started programming Ruby about 1 month ago. Have lots > of experience with vb so the programming concepts are clear to me. I'm > building a script that is using the sample stream of the Twitter API and > insert it into MySQL for analysis. The problem is, that some of the > tweets have a ' in them. I want to replace them with '' so insert into > SQL is not a problem. I have written some piece of code trying to get > this to work, but the output replaces every letter with ''. This is the > code: You're probably going about this the wrong way - your database layer should provide a quoting mechanism for you. For example, if you're using the low-level mysql-ruby then use Mysql.quote(str); if you're using something like ActiveRecord then that handles quoting for you. But to answer your direct question: line.gsub!("'","''") would achieve what you're asking for. -- Posted via http://www.ruby-forum.com/.