<br><br><div><span class="gmail_quote">On 15/06/07, <b class="gmail_sendername">Jim Burton</b> <<a href="mailto:firstname.lastname@example.org">email@example.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Sebastian Sylvan wrote:<br>> On 15/06/07, Jim Burton <<a href="mailto:firstname.lastname@example.org">email@example.com</a>> wrote:<br>[snip]<br>> Hi,<br>Hi Sebastian,<br>> I haven't compiled this, but you get the general idea:
<br>><br>> import qualified Data.ByteString.Lazy.Char8 as B<br>> -- takes a bytestring representing the file, concats the lines<br>> -- then splits it up into "real" lines using the delimiter<br>> clean :: Char ->
B.ByteString -> [B.ByteString]<br>> clean' d = B.split d . B.concat . B.lines<br><br>I think that would only work if there was one column per line...I didn't<br>make it clear that as well as being comma separated, the delimiter is
<br>around each column, of which there are several on a line so if the<br>delimiter is ~ a file might look like:<br><br>~sdlkfj~, ~dsdkjf~ #eo row1<br>~sdf<br>dfkj~, ~dfsd~ #eo row 2</blockquote><div><br><br>A sorry, I thought the delimiter was a line delimiter. I'm trying to get to that fusion goodness by using built-in functions as much as possible...
<br><br>How about this one:<br><br>clean del = B.map ( B.filter (/='\n') ) . B.groupBy (\x y -> (x,y) /= (del,'\n'))<br></div><br></div>That groupBy will group it into groups which don't have the delimiter followed by a newline in them (which is the sequence your rows end with), then it filters out newlines in each row. You might want to filter out spaces first (if there are any) so that you don't get a space between the delimiter and newline at the end...
<br><br clear="all"><br>-- <br>Sebastian Sylvan<br>+44(0)7857-300802<br>UIN: 44640862