๐Ÿ”ก 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