[Haskell-cafe] Converting [Word8] to String

Glynn Clements glynn at gclements.plus.com
Tue Oct 4 19:23:12 EDT 2005


Tomasz Zielonka wrote:

> > How do I convert a list of bytes to a string?
> 
> I assume you don't care about Unicode:

That should have said "I assume that the data is encoded using
ISO-8859-1 (or a subset thereof, e.g. US-ASCII)".

> map (Char.chr . fromIntegral)
> 
> or
> 
> map (toEnum . fromEnum)

For anything else, you will have to either to write a decoder (or use
someone else's; several exist for UTF-8), or interface to iconv()
using the FFI.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the Haskell-Cafe mailing list