How can I read the bytes of a String
in dart?
in Java it is possible through the String
method getBytes()
.
import 'dart:convert';
String foo = 'Hello world';
List<int> bytes = utf8.encode(foo);
print(bytes);
Output: [72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
Also, if you want to convert back:
String bar = utf8.decode(bytes);