ruseel
ruseel

Reputation: 1734

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}\""

Upvotes: 2

Views: 4307

Answers (1)

SCouto
SCouto

Reputation: 7928

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

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

Upvotes: 8

Related Questions