Convert String to UTF-8 bytes

128 views Asked by At

How do I encode a String in Ceylon as UTF-8 bytes?

value string = "my_string";
[Byte*] bytes = string.______;
1

There are 1 answers

2
Lucas Werkmeister On BEST ANSWER

Use ceylon.buffer.charset.

import ceylon.buffer.charset {
    utf8
}

shared void run() {
    value string = "my_string";
    List<Byte> bytes = utf8.encode(string);
    Byte[] bytesSequence = bytes.sequence(); // in case a List isn’t enough
}

Try it!