toiavalle February 2016

Multiline Strings in Swift

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

Answers


Price Ringo February 2016

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

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

enter image description here

Post Status

Asked in February 2016
Viewed 2,309 times
Voted 13
Answered 1 times

Search




Leave an answer