Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline Strings in Swift [duplicate]

How can I create a multiline string in Swift? This is what I tried:

var myMultilineString = "This is a " + "\n" + "multiline string"
print(myMultilineString)

I wanted it to print:

This is a

multiline string

like image 260
toiavalle Avatar asked Mar 14 '23 08:03

toiavalle


2 Answers

Swift4 has this feature built in:

var myMultilineString =
"""
This is a

multiline string
"""

very convenient

like image 186
Ciprian Rarau Avatar answered Mar 23 '23 20:03

Ciprian Rarau


If you want more than a line return between the strings but rather a real blank line, then you need two line feed characers.

var myMultilineString = "This is a " + "\n\n" + "multiline string"
print(myMultilineString)

enter image description here

like image 41
Price Ringo Avatar answered Mar 23 '23 18:03

Price Ringo