[Haskell-cafe] How do I use ByteString?

Ivan Miljenovic ivan.miljenovic at gmail.com
Mon Apr 5 21:32:36 EDT 2010


2010/4/6 Günther Schmidt <gue.schmidt at web.de>:
> I initially start with Strings, ie. [Char], but there is no function to
> convert the 2 back and forth. There is however a function which takes
> [Word8] to BytesString and back.

The problem is one of encoding.  If you use the Char8 Bytestring
variants, then pack and unpack will return Strings... as long as
you're OK using only those characters that can fit in 8 bytes.

utf8-string lets you do conversions to/from Bytestring if you know the
String in question is UTF-8; otherwise, if you use the Text library
you have a variety of encodings to choose from.


-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list