Swift Basics: Multi-Line Strings
Learn about multi-line strings in the Swift Programming Language
Imagine that you’re a chef and you want to share a recipe with your friends. Instead of just listing the ingredients and instructions in a boring old list, you want to add some personality and flair to your recipe by writing it in a more story-like format. This is where multi-line strings come in handy!
A multi-line string in Swift is a series of characters (letters, numbers, symbols, etc.) that span multiple lines and are enclosed in triple quotation marks (“””). Here’s an example of a simple multi-line string:
As you can see, the multi-line string starts with triple quotation marks and ends with triple quotation marks, and everything in between is part of the string. This makes it easy to write a recipe or any other long piece of text that needs to be formatted a certain way.
Now, let’s say you want to add some emphasis to certain parts of your recipe by making them bold. You can do this using something called string interpolation. String interpolation lets you insert variables or expressions into a string by wrapping them in parentheses and prefixing them with a backslash ().
Here’s an example of how you could use string interpolation to make the ingredients in your recipe bold:
Now, when you print out the boldIngredients
string, the ingredients will be displayed in bold.
Multi-line strings are a great way to add some personality and formatting to your code, whether you’re writing a recipe or something else entirely.
🤟 If this article helps you, help someone else and share it.
🌮 BuyMeATaco if you’re in a generous mood.