What is the best way to convert a String to a ByteString in Haskell?
My gut reaction to the problem is
import qualified Data.ByteString as B
import Data.Char (ord)
packStr = B.pack . map (fromIntegral . ord)
But this doesn't seem satisfactory.
What is the best way to convert a String to a ByteString in Haskell?
My gut reaction to the problem is
import qualified Data.ByteString as B
import Data.Char (ord)
packStr = B.pack . map (fromIntegral . ord)
But this doesn't seem satisfactory.
Data.ByteString[.Lazy].Char8.pack
You can typically use hoogle to find functions.
Data.ByteString.UTF8.fromString is also useful. The Char8 version will lose the unicode-ness and UTF8 will make a UTF8-encoded ByteString. You have to choose one or the other.