2

My method receives a String argument.

That String represents source code, which can contain another string.

The problem is that now I want to have a quoted string inside a quoted string, and the compiler doesn't accept it.

obj mymethod:
  'mymethod: arg
   Transcript show: 'code to make noise';cr. "This is the method code"
  '.

How can I write string inside a string (i.e., how can I include a string quote character ' inside a string) ?

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
Ohad
  • 1,563
  • 2
  • 20
  • 44

1 Answers1

4

You have to escape single quote in string with another single quote. So you have to do:

obj mymethod:
  'mymethod: arg
   Transcript show: ''code to make noise'';cr. "This is the method code"
  '.
Uko
  • 13,134
  • 6
  • 58
  • 106