Literals/String: Difference between revisions

→‎{{header|Swift}}: Added Swift multi-line string literals
mNo edit summary
(→‎{{header|Swift}}: Added Swift multi-line string literals)
Line 2,563:
Like this
</pre>
 
 
Swift 4 introduced multi-line string literals called long strings. Long strings are strings delimited by <code>"""triple quotes"""</code> that can contain newlines and individual <code>"</code> characters without the need to escape them.
 
<lang Swift>let author = "Author"
let xml == """
<?xml version="1.0"?>
<catalog>
<book id="bk101" empty="">
<author>\(author)</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book>
</catalog>
"""
 
println(xml)</lang>
{{out}}
<pre>
<?xml version="1.0"?>
<catalog>
<book id="bk101" empty="">
<author>Author</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book>
</catalog>
</pre>
 
To allow free formatting of the literal an indentation stripping operation is applied whereby any whitespace characters in front of the closing delimiter are removed from each of the lines in the literal. As part of this process any initial linefeed is also removed. This allows the developer to paste literal content directly into the string without modification.
 
=={{header|Tcl}}==
5

edits