convert 方法

Uint8List convert(
  1. String string,
  2. [int start = 0,
  3. int? end]
)
继承

String 转换为其代码单元的列表。

如果提供了 startend,则仅使用 substring string.substring(start, end) 作为转换的输入。

实现

Uint8List convert(String string, [int start = 0, int? end]) {
  var stringLength = string.length;
  end = RangeError.checkValidRange(start, end, stringLength);
  var length = end - start;
  var result = Uint8List(length);
  for (var i = 0; i < length; i++) {
    var codeUnit = string.codeUnitAt(start + i);
    if ((codeUnit & ~_subsetMask) != 0) {
      throw ArgumentError.value(
          string, "string", "Contains invalid characters.");
    }
    result[i] = codeUnit;
  }
  return result;
}