<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Thanks. <BR>
<BR>
import Text.ParserCombinators.Parsec <BR>
<BR>
simple = between (char '"') (char '"') (many (satisfy (/= '"')))<BR><BR>
multiple = sepBy simple (char ',') <BR>total = sepBy multiple (char <A href="mailto:'@'">'@'</A>) <BR>
<BR>
str2lsts :: String -> [[String]]<BR>str2lsts str= case parse total "" str of<BR> Left err -> error (show err)<BR> Right lsts -> lsts<BR>
<BR>
solves my problem. As you can see I've replaced '§' with <A href="mailto:'@'">'@'</A> and now all works fine.<BR>
<BR>
Luca. <BR> <BR>> From: daniel.is.fischer@web.de<BR>> To: beginners@haskell.org<BR>> Subject: Re: [Haskell-beginners] beginner question<BR>> Date: Fri, 30 Oct 2009 15:46:33 +0100<BR>> <BR>> Am Freitag 30 Oktober 2009 14:40:13 schrieb Luca Ciciriello:<BR>> > Hi all.<BR>> ><BR>> > Just a very basic question.<BR>> ><BR>> ><BR>> ><BR>> > I need to write a function str2lsts :: String -> [[String]] in order to<BR>> > transorm a string like:<BR>> ><BR>> ><BR>> ><BR>> > "\"1\",\"cat\",\"dog\"§\"2\",\"duck\",\"goose\""<BR>> ><BR>> ><BR>> ><BR>> > in the list of lists:<BR>> ><BR>> ><BR>> ><BR>> > [["1","cat","dog"],["2","duck","goose"]]<BR>> ><BR>> ><BR>> ><BR>> > I've tried to mix recursion, pattern matching and list comprehension, but<BR>> > the obtained result was embarrassing complex (> 20 lines of awful code). I<BR>> > think that a more simple solution certainly exists.<BR>> ><BR>> <BR>> splitOnToken :: Eq a => a -> [a] -> [[a]]<BR>> splitOnToken t xs<BR>> = case break (== t) xs of<BR>> (hd,tl) -> hd:case tl of<BR>> (_:r@(_:_)) -> splitOnToken t r<BR>> _ -> []<BR>> <BR>> str2lsts = map (map read . splitOnToken ',') . splitOnToken '§'<BR>> <BR>> if things weren't enclosed in quotation marks inside the string, it would be the nicer<BR>> <BR>> map (splitOnToken ',') . splitOnToken '§'<BR>> <BR>> , provided of course, neither ',' nor '§' are valid characters for the target strings.<BR>> <BR>> import Text.ParserCombinators.Parsec<BR>> <BR>> simple = between (char '"') (char '"') (many (staisfy (/= '"')))<BR>> -- alternative: simple = char '"' >> manyTill anyChar (char '"')<BR>> <BR>> multiple = sepBy simple (char ',')<BR>> <BR>> total = sepBy multiple (char '§')<BR>> <BR>> str2lsts str<BR>> = case parse total "" str of<BR>> Left err -> error (show err)<BR>> Right lsts -> lsts<BR>> <BR>> ><BR>> ><BR>> ><BR>> > Thanks in advance for any idea.<BR>> ><BR>> ><BR>> ><BR>> > Luca<BR>> <BR>> <BR>> _______________________________________________<BR>> Beginners mailing list<BR>> Beginners@haskell.org<BR>> http://www.haskell.org/mailman/listinfo/beginners<BR>                                            <br /><hr />Download Messenger onto your mobile for free. <a href='http://clk.atdmt.com/UKM/go/174426567/direct/01/' target='_new'>Learn more.</a></body>
</html>