File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -42,12 +42,23 @@ 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 on an individual basis using a backslash before the double quote, as follows:
53
+
54
+ val person = "{\"name\":\"James\"}"
55
+
56
+ On longer strings, this may be time intensive. To avoid the need to escape every individual quote, triple quotes can be used as shown:
57
+
58
+ val person = """{"name":"James"}"""
59
+
60
+ Both of these strings, when printed, will produce the string ` {"name":"James"} ` .
61
+
51
62
### The ` f ` Interpolator
52
63
53
64
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