TL ; DR:
To create a string in Swift, we put some text inside double quotes (
"Hello world").Be careful not to forget any quote! This code missing a
"at the end:print("Welcome!)would throw a
SyntaxError
Full lesson:
How boring would our life as humans be if we communicated only using numbers? Luckily we have letters, words and languages to express what we think!
We can also use letters and words in Swift to express more meaningful messages like we do in real life.
Strings:
In programming, a string is any block of text e.g. any sequence of characters from your keyboard (letters, numbers, spaces, symbols, etc.).
To create a string in Swift, we put some text inside double quotes like this "Hello world".
For example, we can use strings inside the print() function for printing messages to the console:
print("My name is Andy")
print("Welcome to AlgoCademy!")
The output of this code is:
My name is Andy
Welcome to AlgoCademy!
As you can see, the quotes are not printed. That's because quotes are not part of the string. Their job is solely to let Swift know when a string declaration starts and when it ends.
Assignment
Follow the Coding Tutorial and let's work with strings!
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. Premium is unlimited.