In a nutshell:
"""I want to be able to
|have the convenient formatting of a multiline string,
|while using inline escape sequences\r\r\b\\
|
|How can this be done?""".stripMargin
In a nutshell:
"""I want to be able to
|have the convenient formatting of a multiline string,
|while using inline escape sequences\r\r\b\\
|
|How can this be done?""".stripMargin
There is a convenient example hidden in the standard library. It's easy to tweak in a couple of ways to add standard processing. It's not obvious how embedded
\r
is intended, however, socaveat interpolator
.Update: for the record, the hard part was forgetting the sequence arg
_*
. Because it's Any*, there's no type error; the underlying interpolator just throws an error that the parts don't match the args.Update: fixed underscore star so it doesn't italicize.
Example:
Here is the StripMargin..or with name changes to protect one's sanity, note the caveat about
raw
:Two options that I can think of:
You can use
StringContext.treatEscapes
directly:If the variable substitution feature of the "simple interpolator" (
s
) isn't disruptive to your needs, then try combining string interpolation (which converts escaped characters) with"""
-quotes (which doesn't escape ...):outputs
For details, see the relevant SIP and this earlier question.
In addition to the other answers - what about this idea?
The only thing that won't work that way is the
\
at the end of the line. In my example, you embed the escaped characters as a normal string, and then use string interpolation to insert them. (Mind thes
before the opening triple quotes.)