Interpolated String messes up escape-chars

Scala-2.12.20:

val correct = """\\s"""
val wrong = s"""\\s"""
Assertions.assertEquals(correct, wrong)

the value of wrong is \s not \\s, any idea why?

It’s a normal behaviour of s-interpolator, probably what you wanted to use is raw-interpolator

Any arbitrary expression can be embedded in ${}.
For some special characters, it is necessary to escape them when embedded within a string. To represent an actual dollar sign you can double it $$,

The raw interpolator is similar to the s interpolator except that it performs no escaping of literals within the string. Here’s an example processed string

1 Like

Thanks