使用Dart将Uint8List转换为字符串 [英] Convert Uint8List to String with Dart

查看:2795
本文介绍了使用Dart将Uint8List转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

cipher.process returns an Uint8List which is a list of unsigned integers (0-255). I need to convert this Uint8List to a string that I can easily convert back to the same Uint8List.

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

ASCII.decode引发错误,因为某些整数大于127.

ASCII.decode throws an error since some of the integers are > 127.

推荐答案

我想应该这样做:

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

这篇关于使用Dart将Uint8List转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆