🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.ruby
Article #158

Re: Problem z '

#158
From: Marcin Mielżyński
Date: Fri, 25 Aug 2006 14:43
32 lines
1900 bytes
janu wrote:
> Witam,
> 
> Juz jakas godzine zmagam sie z pewnym problemem - otoz uzywajac dla
> sciagnietych z dokumentu XMLowego wartosci wywoluje gsub("\'","\\\'"),
> bo docelowo te wartosci chce wypisac jako INSERTy SQLowe. Problem
> polega na tym, ze zamiast pojawiac sie \' zmieniaja mi sie dziwnie te
> wartosci, np. users wishess wishes, zamiast user's wishes. Co z tym
> zrobic, jak to ugryzc zeby bylo prawidlowo? Czuje sie jak totalny
> idiota, bo wydaje mi sie, ze mam wszystko dobrze ;/
> 
> Pozdrawiam
> Jachu
> 

puts "'wishes'".gsub("'","\\\\'")
lub:
puts "'wishes'".gsub("'"){'\\\''}

z:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/90404?help-en


"It does look a bit odd, but the explanation is logical: There are two
levels of escaping involved.  The first level is that needed for the 
ruby parser to get the expected characters into the replacement string.  The
second level is used in order to be able to use a backslash literally in
the substitution string"


lopex
Technical Details
Message-ID: <ecn29a$jp9$1@news.onet.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mail
References: <1156512904.344369.228030@75g2000cwc.googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mail
From: Marcin Mielżyński <lopx@gazeta.pl>
Newsgroups: pl.comp.lang.ruby
Subject: Re: Problem z '
Date: Fri, 25 Aug 2006 16:43:13 +0200
Organization: Onet.pl
Lines: 32
Message-ID: <ecn29a$jp9$1@news.onet.pl>
References: <1156512904.344369.228030@75g2000cwc.googlegroups.com>
NNTP-Posting-Host: cuo178.internetdsl.tpnet.pl
Mime-Version: 1.0
X-Trace: news.onet.pl 1156516970 20265 83.19.70.178 (25 Aug 2006 14:42:50 GMT)
X-Complaints-To: usenet@news.onet.pl
NNTP-Posting-Date: Fri, 25 Aug 2006 14:42:50 +0000 (UTC)
X-Sender: 5Da2qcG7AWj7WISFX859Php/OS6q4VnB
In-Reply-To: <1156512904.344369.228030@75g2000cwc.googlegroups.com>
User-Agent: Thunderbird 1.5.0.5 (Windows/20060719)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit