arrays - 使用 Dart 将 Uint8List 转换为字符串

标签 arrays string dart

cipher.process 返回一个 Uint8List,它是一个无符号整数列表 (0-255)。我需要将此 Uint8List 转换为可以轻松转换回相同 Uint8List 的字符串。

    var cipherText = cipher.process( inputAsUint8List );        
    return ASCII.decode(cipherText);

ASCII.decode 会抛出错误,因为某些整数 > 127。

最佳答案

我想这应该这样做:

String s = new String.fromCharCodes(inputAsUint8List);
var outputAsUint8List = new Uint8List.fromList(s.codeUnits);

关于arrays - 使用 Dart 将 Uint8List 转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28565242/

相关文章:

dart - 如何滑动到右侧的新页面而不是 flutter 的底部?

c - 为什么下面的代码不会在多次运行时生成随机字符串?

C 中的条件语句和数组(初学者)

PHP MySQL 数组,如何获取 API 的特定结构?

android - 如何解析这个json?

string - 字符串列表中的笛卡尔积

java - 获取 "parse exception"

Flutter 值对象工厂构造函数在 Bloc 发出时执行两次

dart - Future.then返回意外的空值

c - 为什么数组变量的地址与自身相同?