Tokenize a string: Difference between revisions

(→‎{{header|Haskell}}: another example)
Line 324:
 
Tokenizing can also be realized by using unfoldr and break:
<lang Haskell>*Main> mapM_ putStrLn $ unfoldrtakeWhile (\xs -> if not.null) xs$ thenunfoldr Nothing(Just else. Just(second(drop 1). break (==',') $ xs)) "Hello,How,Are,You,Today"
Hello
How
Line 331:
Today</lang>
* You need to import the modules Data.List and Control.Arrow
 
As special cases, splitting / joining by white space and by newlines are provided by the Prelude functions <tt>words</tt> / <tt>unwords</tt> and <tt>lines</tt> / <tt>unlines</tt>, respectively.
 
=={{header|Groovy}}==
Anonymous user