On Jul 24, 2013, at 5:34 PM, Mariano Martinez Peck <marianopeck@gmail.com> wrote:
Hi guys. I am a bit lost here and maybe someone can give me a hand. I have a string that may include a single quote inside. Say I have the string 'Sell ''13' . This string actually has a SINGLE quote, so if you print it in a file for example, you get 'Sell '13'. Of course, when you inspect the string in Pharo, it has 2 single quotes: 'Sell '' 13'. ok?
No It still has a single quote. This is just the reader that reads '' and produces ' '1''3' at: 2 $' '1''3' at: 3 $3
Now...what I need is (quite weird I know) is to build a closure as a string and using the previous string as a literal of the closure.
Imagine there is no single quote problem in my string, this would work perfect:
(Compiler evaluate: '[ ', ' Transcript show: ', 'Sell ' surroundedBySingleQuotes, ']') value.
But, if instead of having 'Sell ', I have 'Sell '' 13', like this:
(Compiler evaluate: '[ ', ' Transcript show: ', 'Sell '' 13' surroundedBySingleQuotes, ']') value.
I get a SyntaxError of a unmatched string:
[ Transcript show: 'Sell ' 13Unmatched string quote -> ']
So...what can I do? I GUESS the solution is to scape that. If I try adding 2 more single quotes, like this:
(Compiler evaluate: '[ ', ' Transcript show: ', 'Sell '''' 13' surroundedBySingleQuotes, ']') value.
it seems to work. If this is correct, is there an easy way (a method?) to scape my string automatically so that it works?
Thanks in advance,
-- Mariano http://marianopeck.wordpress.com