Only read from the π§ . When writing to the π§ returned by this method, the behavior is undefined.
Package
Conforms to
Initializers
Methods
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
πβΆοΈππΌ
πβΆοΈππΌ
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.
πβοΈ
βοΈ π
Puts this π‘ to the standard output.
πβοΈ
βοΈ π
Puts this π‘ to the standard output without adding a new line.
ββοΈ
βοΈ β 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
.
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.
π«βοΈ
βοΈ π« 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
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 π―.
ββοΈ
βοΈ β β‘οΈ π’
Hashes this string. The results for strings whose values equal are guaranteed to be the same within a process.
π«βοΈ
βοΈ π« β‘οΈ π‘
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.
π‘βοΈ
βοΈ π‘ β‘οΈ π‘