Cuis-Automatically escape a complex string

From Cuis CookBook
Jump to navigation Jump to search

Problem You have a long shell command, or an SQL command, or something else which may contain tne $' Character. You can escape the $' by doubling it yourself but it will become quite hard to read your original string. Is there a better way?

Solution. Yes, there is a nice trick to achieve that.

  • Suppose the string you want to quote is echo "i'm nicola, who are you?"
  • Open a TextMorph
te := TextEditor openTextEditor .
  • Write the string into it
  • Go back to the Workspace and type this
te model actualContents asString . "=>" 'echo "hello, i''m nicola, who are you?"'
  • Voila', you have your string automatically escaped, notice the doulbe $' character in i''m nicola.
  • Some time ago I made a video tutorial about this with a much worst string. There the procedure is a bit different, it was specific for Squeak.

Dr. Nicola Mingotti firt wrote this on 21-Sep-2021. Tested in Cuis5.0-4834.image