Strings are words or pieces of text that the computer treats as a single item. They provide a way to store something like a word, sentence, or whole paragraph.
Technically speaking, a string is a sequence of characters. It can be of any length and contain any letters, numbers, symbols, or spaces as long as they are surrounded by
Here are four different strings in Emojicode:
🔤This is a string!🔤🔤This is also a string!!!🔤🔤1337🔤🔤👆👍🔤
It’s important to distinguish between strings and the rest of the code in our programs. Every part of a program is made up of characters, but strings are the parts we intend to keep as data—not as instructions to be executed by the computer.
Here’s a full program that print out two strings:
🏁 🍇😀 🔤2020...🔤❗️😀 🔤That was a crazy year.🔤❗️🍉
String interpolation can be used to construct a string from a mix of constants, variables, and others by including their values inside a string literal.
In Emojicode, to insert a value into a string using string interpolation, we can write the variable inside two
🧲s and it will print its value.
Suppose we have a constant named
height with a value of
3000, and we want to use string interpolation to print out a fun fact:
3000 ➡️ height😀 🔤Alex Honnold climbed El Capitan, which is 🧲height🧲 feet, without a rope!🔤❗️
It will output:
Alex Honnold climbed El Capitan, which is 3000 feet, without a rope!
- Anonymous contributorAnonymous contributor3071 total contributions
- Anonymous contributor