[Haskell-cafe] Sneaking haskell in the workplace -- cleaning csv files

Jim Burton jim at sdf-eu.org
Fri Jun 15 18:31:36 EDT 2007

Sebastian Sylvan wrote:
> On 15/06/07, Jim Burton <jim at sdf-eu.org> wrote:
> Hi,
Hi Sebastian,
> I haven't compiled this, but you get the general idea:
> import qualified Data.ByteString.Lazy.Char8 as B
> -- takes a bytestring representing the file, concats the lines
> -- then splits it up into "real" lines using the delimiter
> clean :: Char -> B.ByteString -> [B.ByteString]
> clean' d = B.split d . B.concat . B.lines

I think that would only work if there was one column per line...I didn't 
make it clear that as well as being comma separated, the delimiter is 
around each column, of which there are several on a line so if the 
delimiter is ~ a file might look like:

~sdlkfj~, ~dsdkjf~ #eo row1
dfkj~, ~dfsd~      #eo row 2


More information about the Haskell-Cafe mailing list