Need UTF-8 bytes for your algorithm? Don't want to waste time investigating how to go back and forth between UTF-16 and UTF-8? I hear ya.
Examples in the documentation assume an import like this:
import String.UTF8 as UTF8Convert a String to a sequence of UTF-8 bytes. The inverse of toString.
UTF8.toBytes "✓ a-ok"
--> [ 0xe2, 0x9c, 0x93, 0x20, 0x61, 0x2D, 0x6F, 0x6B ]Convert a sequence of UTF-8 bytes to an Elm UTF-16 String.
UTF8.toString [ 0x68, 0x65, 0x6C, 0x6C, 0x6F ]
--> Ok "hello"
UTF8.toString [ 0xF0, 0x9F, 0x92, 0xA9 ]
--> Ok "💩"If the input is not a valid UTF-8 sequence, you'll receive an error.
UTF8.toString [ 0xF0]
--> Err "invalid UTF-8 sequence"Fold over a string, left to right, accumulating UTF-8 bytes along the way.
Number of UTF-8 codepoints in a string.