Dart – Convert String to Byte array

This post demonstrates a few methods to convert String to Byte array in Dart.

import 'dart:convert';

void main() {
  final coflutter = 'Coflutter';

  print('UTF8        : ${utf8.encode(coflutter)}');

  print('Runes       : ${coflutter.runes.toList()}');

  print('Code units  : ${coflutter.codeUnits}');
}

Output

UTF8        : [67, 111, 102, 108, 117, 116, 116, 101, 114]
Runes       : [67, 111, 102, 108, 117, 116, 116, 101, 114]
Code units  : [67, 111, 102, 108, 117, 116, 116, 101, 114]
Tagged : / / / /
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x