How to create a multiline string in Swift
In this tutorial, we are going to learn about how to make a multiline string in Swift language.
Creating a multiline string
To create a multiline string literal, we can use the three double quotation marks """ syntax in Swift.
Here is an example:
let multilineString = """
Hello you can
write here
multiple lines
"""
print(multilineString)Output:
Hello you can
write here
multiple linesThe multiline string starts after the opening quotation marks """ and ends on the line before closing quotation marks """.
We can also format the final string by removing the line breaks, using the backslash (\) at the end of those lines.
Example:
let multilineString = """
Hello you can \
write here \
multiple lines
Thanks
"""
print(multilineString)Output:
Hello you can write here multiple lines
Thanks

