Search code examples
scalastring-interpolation

How to insert double quotes in s""?


I know that I can do string interpolation with s"", but how can I insert double quotes inside of s""?

scala> val x = "x"
x: String = x

scala> s""
res5: String = ""

scala> s"${x}"
res6: String = x

scala> s"${x}\""
<console>:1: error: unclosed string literal
       s"${x}\""

Solution

  • You just need to surround your String with triple-double quotes:

    scala>  s"""${x}""""
    res1: String = 5"