[Haskell-cafe] splitting strings

h. h._h._h._ at hotmail.com
Thu Mar 1 07:02:57 EST 2007


Hello,

I wrote the following split function for Strings:


splitS :: String -> String -> [String]
splitS a b = splitA a b
    where
    z = length b - 1
    splitA []     _      = [""]
    splitA (c:cs) (d:ds) | c == d && fst s == ds = "" : splitA (snd s) b
                         | otherwise = (c : head r) : tail r
        where
        r = splitA cs b
        s = splitAt z cs


example:  splitS "Test;Hello;+123.5;+ 7" ";+" -> ["Test;Hallo","123.5"," 7"]

How could it be optimized on speed?
Does there exist already an optimized split for the conventional String type?

--
Thanks in advance for your answer.
h.




More information about the Haskell-Cafe mailing list