๐ก Strings
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
- Anonymous contributorAnonymous contributor3071 total contributions
- christian.dinh2476 total contributions
- Anonymous contributor
- christian.dinh
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.