字节转换字符串

/ 默认分类 / 没有评论 / 411浏览

List

import 'dart:convert'
List<int> b=Utf8Codec().encode('hello');
String str=Utf8Codec().decode(b);

UInt8List

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

ByteData

  static String getStringFromBytes(ByteData data) {
    final buffer = data.buffer;
    var list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    return String.fromCharCodes(list);
  }