🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.ruby
3 messages
3 total messages Started by janu Fri, 25 Aug 2006 13:35
Problem z '
#157
Author: janu
Date: Fri, 25 Aug 2006 13:35
12 lines
1523 bytes
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
Re: Problem z '
#158
Author: 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
Re: Problem z '
#159
Author: janu
Date: Fri, 25 Aug 2006 16:24
21 lines
1869 bytes
Marcin Mielżyński wrote:
> 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"

Rzeczywiscie, pomoglo, dzieki wielkie. Sobie wlasnie przypomnialem, ze
o tym chyba pisali w Programming Ruby - the pragmatic costam ;)...

Pozdrawiam
Jachu
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads