Last active
August 29, 2015 14:19
-
-
Save kevinadi/da8fbd30b3e03300ce56 to your computer and use it in GitHub Desktop.
Haskell: split a string using a substring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
splitStr :: Eq a => [a] -> [a] -> [[a]] | |
splitStr sub str = split' sub str [] [] | |
where | |
split' _ [] subacc acc = reverse (reverse subacc:acc) | |
split' sub str subacc acc | |
| sub `isPrefixOf` str = split' sub (drop (length sub) str) [] (reverse subacc:acc) | |
| otherwise = split' sub (tail str) (head str:subacc) acc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment