this function should tokenize a String:
split s c xs i j =
if head s == c
then split s c (subStr s i j : xs) j (j + 1)
else if j == length s
then (subStr s i j) : xs
else split s c xs i j + 1
subStr s i j = take j(drop i s)
However I get the following error msg: No instance for (Num [[Char]]) arising from a use of 'split' Possible fix: add an instance declaration at (Num [[Char]])
Thanks.
Ok function is now:
split s c xs i j =
if j == length s
then (subStr s i j) : xs
else if head (drop j s) == c
then split s c (subStr s i j : xs) (j + 1) (j + 1)
else split s c xs i (j + 1)
subStr s i j = take j(drop i s)
now when I apply the function with the following args: split "123,456,789" ',' [] 0 0 I get the result ["789", "456,789", "123"] what's happening here?
j+1
on the second to last line. – genisagesubstr s i j = take (j-i) (drop i s)
– genisage