Strings
You write a string between two 🔤. Its type is 🔡.
Interpolating values (🧲)
Inside a string, whatever you put between 🧲 and 🧲 is replaced by the value of a variable or expression.
🏁 🍇
🔤Emoji🔤 ➡️ name
😀 🔤Hello, name!🔤❗️
😀 🔤1 ➕ 2 is 1 ➕ 2🔤❗️
😀 🔤Half is 1.5🔤❗️
🍉Hello, Emoji! 1 ➕ 2 is 3 Half is 1.500000
What goes inside 🧲 must be a value of a type that can be turned into a string. Strings, integers, and real numbers work, but Booleans, lists, and optionals can't go in as they are. Real numbers are shown with 6 decimal places, so if you want to choose the number of digits, turn the number into a string first with 🔡 real digits❗️ from “Converting to and from numbers” below.
🏁 🍇
🔢 🔤12🔤 10❗️ ➡️ n
😀 🔤n is n🔤❗️
🍉is not compatible to
Unwrap an optional before putting it in (Optionals). Your own types can go inside 🧲 too, if they provide ❗️ 🔡 ➡️ 🔡 and conform to the protocol ↘️🔸🔡 (Protocols).
Special characters (❌)
To write a newline, a tab, 🔤 itself, and so on inside a string, put ❌ in front of it.
| Syntax | Meaning |
|---|---|
❌n |
Newline |
❌t |
Tab |
❌🔤 |
The character 🔤 |
❌🧲 |
The character 🧲 |
❌❌ |
The character ❌ |
🏁 🍇
😀 🔤Line 1❌nLine 2🔤❗️
😀 🔤❌🔤 for strings, ❌🧲 for interpolation🔤❗️
🍉Line 1 Line 2 🔤 for strings, 🧲 for interpolation
Converting to and from numbers
Number → string
🔡 number❗️ turns an integer into a decimal string. A second argument lets you choose the base (radix).
🏁 🍇
😀 🔡 255❗️❗️
😀 🔡 255 16❗️❗️
😀 🔡 255 2❗️❗️
🍉255 ff 11111111
For a real number, 🔡 number digits❗️ lets you choose how many digits after the decimal point to output.
🏁 🍇
😀 🔡 2.5 1❗️❗️
😀 🔡 2.5 3❗️❗️
🍉2.5 2.500
When a real number is turned into a string, digits beyond the ones you asked for are truncated, not rounded (
🔡 3.05 2❗️can even become3.04). This is a bug in the official compiler. See Emojicode Language Bugs for details.
String → number
🔢 string base❗️ turns a string into an integer.
A string can't always be read as a number, so the result is 🍬🔢 (an optional), which means “an integer, or no value.” To unwrap it, use ↪️ … ➡️ name.
🏁 🍇
↪️ 🔢 🔤42🔤 10❗️ ➡️ n 🍇
😀 🔡 n ➕ 1❗️❗️
🍉
↪️ 🔢 🔤forty-two🔤 10❗️ ➡️ n 🍇
😀 🔤Never gets here🔤❗️
🍉
🙅 🍇
😀 🔤Not a number🔤❗️
🍉
🍉43 Not a number
↪️ and 🙅 are conditionals (if and else). Optionals are covered in detail in a later chapter.
Common methods
| Syntax | Result |
|---|---|
📫 string❗️ |
Convert to uppercase |
📪 string❗️ |
Convert to lowercase |
🔪 string start length❗️ |
Take out part of it (position and length count visible characters) |
🔧 string❗️ |
Remove whitespace at both ends |
🔫 string separator❗️ |
Split at the separator into a list (🍨🐚🔡🍆) |
🔍 string search❗️ |
The position where it was found (🍬🔢) |
🎼 string prefix❗️ / ⛳️ string suffix❗️ |
Whether it starts / ends with that string (👌) |
🏁 🍇
😀 📫 🔤emojicode🔤❗️❗️
😀 🔪 🔤🍎🍌🍇🍑🔤 1 2❗️❗️
😀 🔧 🔤 surrounding spaces 🔤❗️❗️
↪️ 🎼 🔤🍇🍉🔤 🔤🍇🔤❗️ 🍇
😀 🔤Starts with 🍇🔤❗️
🍉
🍉EMOJICODE 🍌🍇 surrounding spaces Starts with 🍇
Positions in 🔪 count from 0. It takes 2 characters starting at position 1 of 🍎🍌🍇🍑, so the result is 🍌🍇. Even if an emoji is made of several code points, it counts as one visible character.
📐 string❗️returns the number of bytes in UTF-8, not the number of characters.📐 🔤えもじ🔤❗️is 9.
Comparing strings
🙌 checks whether two strings are the same.
🏁 🍇
🔤abc🔤 ➡️ a
↪️ a 🙌 🔤abc🔤 🍇
😀 🔤Same🔤❗️
🍉
🍉Same