【发布时间】:2012-12-26 22:44:09
【问题描述】:
所以我想访问字符串的 UTF-8 编码的各个字节。
我尝试使用Data.ByteString.Char8.pack,但这似乎只是将其截断到每个字符的最后一个字节:
ghci> Char8.pack "\945\946\947"
"\177\178\179"
如果我可以从文件中读取字符串,这不是问题:
ghci> Prelude.writeFile "temp.txt" "\945\946\947" >> Char8.readFile "temp.txt"
"\206\177\206\178\206\179"
但我想要一种纯粹的方式来转换 String -> ByteString 而不截断,以及 hoogle isn't very helpful。
【问题讨论】:
-
我记得读过一些关于 hayoo 的文章,其中搜索的包比 hoogle 多,所以我tried your search there,它给了我第二个结果的正确答案:
标签: haskell utf-8 bytestring