Can anybody recommend a way to parse CSV files with options to:
There is the Data.Csv module on hackage. In case your distribution does not provide a package for it you can install it via cabal, e.g.
$ cabal install cassava
It can read and write (i.e. decode/encode) records from/to CSV files.
You can set the field separator like this:
import Data.Csv
import Data.Char -- ord
import qualified Data.ByteString.Lazy.Char8 as B
enc_opts = defaultEncodeOptions {
encDelimiter = fromIntegral $ ord '\t'
}
write_csv vector = do
B.putStr $ encodeWith enc_opts vector
Currently, Data.Csv
does not offer other encode/decode options. There are function variants for working with a header row. As is, lines are terminated with CRLF, double-quotes are used for quoting and as text-encoding UTF8 is assumed. Double-quotes in values are quoted with a back-slash and quoting is omitted where it is 'not necessary'.