[Haskell-cafe] How to split this string.
max
mk at mtw.ru
Mon Jan 2 13:12:02 CET 2012
В Mon, 02 Jan 2012 11:12:49 +0000
Jon Fairbairn <jon.fairbairn at cl.cam.ac.uk> пишет:
> max <mk at mtw.ru> writes:
>
> > I want to write a function whose behavior is as follows:
> >
> > foo "string1\nstring2\r\nstring3\nstring4" = ["string1",
> > "string2\r\nstring3", "string4"]
> >
> > Note the sequence "\r\n", which is ignored. How can I do this?
>
> cabal install split
>
> then do something like
>
> import Data.List (groupBy)
> import Data.List.Split (splitOn)
>
> rn '\r' '\n' = True
> rn _ _ = False
>
> required_function = fmap concat . splitOn ["\n"] . groupBy rn
>
> (though that might be an abuse of groupBy)
>
This is the simplest solution of the proposed, in my opinion. Thank you
very much.
More information about the Haskell-Cafe
mailing list