Search code examples
smalltalksqueak

how can I write string inside a string in Squeak?


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) ?


Solution

  • 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"
      '.