Convert <int> list to string in dart?

I read the file and got 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 the List<int> part to String .

To be more specific, I want to encode a 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.

+6
source share
3 answers

String.fromCharCodes(List<int> charCodes) is probably what you are looking for.

  List<int> charCodes = const [97, 98, 99, 100]; print(new String.fromCharCodes(charCodes)); 
+9
source

You can use the dart: convert library that provides the UTF-8 codec:

 import 'dart:convert'; void main() { List<int> charCodes = [97, 98, 99, 100]; String result = UTF8.decode(charCodes); print(result); } 
+5
source

As already mentioned, String.fromCharCodes(List<int> charCodes) is most likely you are looking for if you want to convert Unicode characters to string. If, however, all you need to do is combine the list into a string, which you can use Strings.join(List<String> strings, String separator) .

 Strings.join([1,2,3,4].map((i) => i.toString()), ",")) // "1,2,3,4" 
+4
source

Source: https://habr.com/ru/post/921609/


All Articles