6. Escaping quotes and line terminators in text blocks
Escaping double quotes is necessary only when we want to embed, in the text block, the sequence of three double quotes ("""
), as follows:
String txt = """
She told me
\"""I have no idea what's going on\"""
""";
Escaping """
can be done with \"""
. There is no need to write \"\"\"
.
The resulting string will look like this:
She told me
"""I have no idea what's going on"""
Whenever you need to embed "
or ""
, simply do it as follows:
String txt = """
She told me
"I have no idea what's going on"
""";
String txt = """
She told me
""...