Tokenize a string: Difference between revisions

→‎{{header|Haskell}}: another example
(→‎{{header|Haskell}}: arg of mkRegex must be a String)
(→‎{{header|Haskell}}: another example)
Line 322:
import Text.Regex
putStrLn $ joinWith "." $ splitRegex (mkRegex ",") $ "Hello,How,Are,You,Today"</lang>
 
Tokenizing can also be realized by using unfoldr and break:
<lang Haskell>*Main> mapM_ putStrLn $ unfoldr (\xs -> if null xs then Nothing else Just(second(drop 1). break (==',') $ xs)) "Hello,How,Are,You,Today"
Hello
How
Are
You
Today</lang>
* You need to import the modules Data.List and Control.Arrow
 
=={{header|Groovy}}==
Anonymous user