Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a UTF-8 String into an array of bytes in Dart?

Tags:

I'm creating a Redis client and would like to create a byte array for sending to the Redis server. To issue commands to the server, I need to convert Dart's UTF-8 strings into a bytes which can be written to a socket.

How can I do this?

like image 918
Mark B Avatar asked May 01 '12 20:05

Mark B


1 Answers

For Dart >1.0 this is now done with the convert library.

import 'dart:convert'; List<int> bytes = utf8.encode("Some data"); print(bytes) //[115, 111, 109, 101, 32, 100, 97, 116, 97] 
like image 86
Delaney Avatar answered Oct 23 '22 16:10

Delaney