Emojicode Documentation 1.0 beta 2

Class πŸ”‘

Strings.

In Emojicode strings are strictly used to represent textual data, i.e. strings are not used to store binary data or the like. If you need to work with binary data see πŸ“‡.

Characters, Graphemes and Random Access

Due to the complexity of working with text, πŸ”‘ does not support random access. For instance, consider this character ν•œ. To a human being, this is one character. Yet, it actually consists of three Unicode code points, as this is the characters γ…Ž, ㅏ and γ„΄ combined. An even better example is βœ‹πŸΎ (you should see a raised hand with darker skin color). While this is one emoji, it is composed by two Unicode code points and encoded with seven bytes in UTF-8.

Unicode defines βœ‹πŸΎ and ν•œ as graphemes. A grapheme is what humans would recognize as one character.

Emojicode only allows you to access these graphemes. Finding graphemes is not a constant-time operation, though. Random access is not possible, therefore.

If you need to deal with the graphemes of a string, you can use the πŸŽΆβ—οΈ method, which returns an array of graphemes. Graphemes are always represented as strings.

To determine the number of graphemes in a string, you can use πŸ“ on that array. To determine the number of UTF-8 bytes that make up a string, use πŸ“.

Mutability

Strings are immutable. This means that you can’t modify any string. You can, however, call methods on strings that return modified copies of the orginal string, but those themselves are then immutable again.

String Literals and Interpolation

To learn more about πŸ”€πŸ”€ String Literals and 🧲 Interpolation see the Language Reference.

Initializers

πŸ†•

☣️  πŸ†•  memory 🧠  count πŸ”’ 

Creates a πŸ”‘ by copying the memory from the memory.

πŸ†•β–ΆοΈπŸ‘‚πŸΌ

 πŸ†•β–ΆοΈπŸ‘‚πŸΌ 

Waits for the user to input a text and confirm it with enter. No new line character is included as part of the string. (Via the standard input/output)

πŸ†•

 πŸ†•  list πŸ¨πŸšπŸ”‘πŸ†  separator πŸ”‘ 

Creates a string by joining all elements into a string separated by separator.

Methods

πŸ§ β—οΈ

❗️ 🧠 ➑️ 🧠

Returns the 🧠 storing the value of this πŸ”‘. No copy is performed.

Hint

Only read from the 🧠. When writing to the 🧠 returned by this method, the behavior is undefined.

πŸ˜€β—οΈ

❗️ πŸ˜€ 

Puts this πŸ”‘ to the standard output.

πŸ‘„β—οΈ

❗️ πŸ‘„ 

Puts this πŸ”‘ to the standard output without adding a new line.

πŸ™Œ

 πŸ™Œ  b πŸ”‘ ➑️ πŸ‘Œ

Returns πŸ‘ if this string is equal to b.

↔❗️

❗️ ↔  b πŸ”‘ ➑️ πŸ”’

Compares this string to b and returns -1, 0, or 1 depending on whether this string is less than, equal to, or greater than b.

Caution

Note that this method compares the strings byte per byte and is only meant for use with non-localized sorting. The results of the sort will always be the same, but may not appear logical to human beings.

πŸ”ͺ❗️

❗️ πŸ”ͺ  from πŸ”’  length πŸ”’ ➑️ πŸ”‘

Returns a new string consisting of length graphemes beginning from the grapheme at index from in this string. Complexity: O(n).

For instance:

πŸ”ͺπŸ”€πŸ‡¦πŸ‡½πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘§πŸ€šπŸΎπŸ”€ 1 1❗️ πŸ’­ returns πŸ”€πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘§πŸ”€
πŸ”ͺπŸ”€ApplesπŸ”€ 2 4❗️ πŸ’­ returns πŸ”€plesπŸ”€

πŸ”β—οΈ

❗️ πŸ”  search πŸ”‘ ➑️ πŸ¬πŸ”’

Finds the first occurrences of search in this string. Search is performed from left to right.

Returns the index of the first occurrence or no value if search does not occur.

πŸ•΅β€β™€β—οΈ

❗️ πŸ•΅β€β™€  search πŸ”‘  offset πŸ”’ ➑️ πŸ¬πŸ”’

Finds the first occurrences of a string in this string after the index offset. Search is performed from left to right.

Returns the index of the occurrence or no value if search does not occur.

πŸŽΌβ—οΈ

❗️ 🎼  testString πŸ”‘ ➑️ πŸ‘Œ

Whether this strings begins with another string.

⛳❗️

❗️ β›³  testString πŸ”‘ ➑️ πŸ‘Œ

Whether this strings ends with another string.

πŸ”«β—οΈ

❗️ πŸ”«  separator πŸ”‘ ➑️ πŸ¨πŸšπŸ”‘πŸ†

This string is split up into substring at each place seperator is found. seperator itself is removed from the string.

πŸ”§β—οΈ

❗️ πŸ”§ ➑️ πŸ”‘

The πŸ”§ method returns a new string, on which whitespace has been removed from both ends of a string.

πŸ“β—οΈ

❗️ πŸ“ ➑️ πŸ”’

Returns the number of bytes required to represent the string’s content in UTF8.

For example:

πŸ“πŸ”€βœ‹πŸΎπŸ”€β—οΈ  πŸ’­ returns 7
πŸ“πŸ”€ν•œπŸ”€β—οΈ  πŸ’­ returns 3
πŸ“πŸ”€AπŸ”€β—οΈ  πŸ’­ returns 1
Hint

The return value is not at all meaningful from a human perspective. The character Γ€ for instance, is encoded with two bytes but clearly perceived as one character.

πŸ”’β—οΈ

❗️ πŸ”’  base πŸ”’ ➑️ πŸ¬πŸ”’

This methods tries to construct an integer from this string in the given base. It returns the integer or no value if the string does not match the regular expression [+-]?[0-9a-zA-Z]+ or it does not represent a valid value in the given base.

πŸ’―β—οΈ

❗️ πŸ’― ➑️ πŸ¬πŸ’―

This methods tries to construct a πŸ’― from this πŸ”‘. It returns the πŸ’―, or no value if the πŸ”‘ does not match the regular expression [+-]?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+-]?[0-9]+)? or if it does not represent a valid πŸ’―.

πŸ“‡β—οΈ

❗️ πŸ“‡ ➑️ πŸ“‡

Converts the string to data encoded as UTF8.

βš—β—οΈ

❗️ βš— ➑️ πŸ”’

Hashes this string. The results for strings whose values equal are guaranteed to be the same within a process.

πŸŽΆβ—οΈ

❗️ 🎢 ➑️ πŸ¨πŸšπŸ”‘πŸ†

Returns an array with the graphemes from this string.

πŸ“«β—οΈ

❗️ πŸ“« ➑️ πŸ”‘

Returns a new string in which all characters have been converted to their respective uppercase equivalents.

πŸ“ͺ❗️

❗️ πŸ“ͺ ➑️ πŸ”‘

Returns a new string in which all characters have been converted to their respective lowercase equivalents.

πŸ‘β—οΈ

❗️ 🍑 ➑️ πŸ‘πŸšπŸ”‘πŸ†

Returns an iterator to iterate over the graphemes of this string.

πŸ”‘β—οΈ

❗️ πŸ”‘ ➑️ πŸ”‘