Skip to content

Commit 38e38f0

Browse files
committed
Update obsolete note on escapes in interpolations
1 parent 4a11252 commit 38e38f0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/_docs/reference/changed-features/interpolation-escapes.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ title: "Escapes in interpolations"
44
nightlyOf: https://docs.scala-lang.org/scala3/reference/changed-features/interpolation-escapes.html
55
---
66

7-
In Scala 2 there is no straightforward way to represent a single quote character `"` in a single quoted interpolation. A `\` character can't be used for that because interpolators themselves decide how to handle escaping, so the parser doesn't know whether the `"` character should be escaped or used as a terminator.
7+
Scala 3 allows `"` (Unicode Quotation Mark) in an interpolation that uses `"` as a delimiter.
88

9-
In Scala 3, we can use the `$` meta character of interpolations to escape a `"` character. Example:
9+
The quotation mark must be escaped by either `$` (Dollar Sign) or `\` (Reverse Solidus or "backslash").
10+
11+
Note that `\` may also escape `"` in an ordinary string. This behavior is consistent with Scala 2.
1012

1113
```scala
1214
val inventor = "Thomas Edison"
13-
val interpolation = s"as $inventor said: $"The three great essentials to achieve anything worth while are: Hard work, Stick-to-itiveness, and Common sense.$""
15+
val essentials =
16+
s"As $inventor said: $"The three great essentials to achieve anything worthwhile are, first, hard work; second, stick-to-itiveness; third, common sense.$""
17+
val perspiration = "interpolation"
18+
val attribution =
19+
s"As $inventor wrote in a letter in 1927: \"It is quite true I once made the statement that genius is one percent inspiration and 99 percent $perspiration, and I am still of the same opinion.\""
1420
```

0 commit comments

Comments
 (0)