Convert a List<int> into a String in Dart?

Viewed 25754

I have read a file and got myself a list of integers. For most of my work this is what I want to get, but in one case I also need to convert some of List<int> into a String.

To be more specified, I want to encode the string in UTF-8.

This is what I just tried:

var decoder = new Utf8Decoder(figures);
print(decoder.decodeRest());

But all I get is a list of integers.

4 Answers

You can use the dart:convert library which provides an UTF-8 codec but be sure to use utf8 all small to use its methods.

List<int> byteArray = [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100];
String result = utf8.decode(byteArray);
List<int> orginal = utf8.encode(result);
Related