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 : / / / /
Subscribe
Notify of
guest

1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Harry Oniel
Harry Oniel
1 year ago

Thanks

1
0
Would love your thoughts, please comment.x
()
x