String interpolation with triple quotes and multiple lines

0__ picture 0__ · Apr 16, 2013 · Viewed 10.3k times · Source

I'm getting stange results from triple """ quoted strings when using string interpolation and line breaks:

val foo = "bar"

s"""$foo"""

This is ok.

s"""
$foo
"""    

This is wrong, I get the following output:

"
bar
"

Why the heck are there quotation marks?

Answer

Impredicative picture Impredicative · Apr 16, 2013

This is just the REPL surrounding multi-line strings in quotation marks. You'll find the actual string contains no quotation marks:

res0.contains("\"")
res1 : Boolean = false