File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -42,12 +42,19 @@ String interpolators can also take arbitrary expressions. For example:
42
42
43
43
will print the string `1 + 1 = 2`. Any arbitrary expression can be embedded in `${}`.
44
44
45
+ For some special characters, it is necessary to escape them when embedded within a string.
45
46
To represent an actual dollar sign you can double it `$$`, like here:
46
47
47
48
println(s"New offers starting at $$14.99")
48
49
49
50
which will print the string `New offers starting at $14.99`.
50
51
52
+ Double quotes also need to be escaped. This can be done by using triple quotes as shown:
53
+
54
+ val person = """{"name":"James"}"""
55
+
56
+ which will produce the string `{"name":"James"}` when printed.
57
+
51
58
### The `f` Interpolator
52
59
53
60
Prepending `f` to any string literal allows the creation of simple formatted strings, similar to `printf` in other languages. When using the `f`
You can’t perform that action at this time.
0 commit comments