Warm tip: This article is reproduced from serverfault.com, please click

其他-如何在Dart中获取字符串的字节?

(其他 - How to get bytes of a String in Dart?)

发布于 2019-02-23 17:25:12

如何读取String dart 中a的字节在Java中,可以通过String方法实现getBytes()

看例子

Questioner
gyorgio88
Viewed
0
Miguel Ruivo 2019-08-17 10:06:06
String foo = 'Hello world';
List<int> bytes = utf8.encode(foo);
print(bytes);

输出:[72、101、108、108、111、32、119、111、114、108、100]

另外,如果你要转换回:

String bar = utf8.decode(bytes);