πŸ”‘ Strings

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Aug 3, 2021Updated Sep 9, 2021
Contribute to Docs

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 πŸ”€β€˜s.

Syntax

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.

Example

Here’s a full program that print out two strings:

🏁 πŸ‡
πŸ˜€ πŸ”€2020...πŸ”€β—οΈ
πŸ˜€ πŸ”€That was a crazy year.πŸ”€β—οΈ
πŸ‰

String Interpolation

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!

All contributors

Looking to contribute?

Learn Emojicode on Codecademy