Chopping a long string into smaller ones toy
I made a great tool I can't do without from now on! ;-D Update#1: added null string checking, renamed "i" to "s". Update#2: upgraded output format, added BASH version! Here's the Haskell source code: import System.Environment(getArgs) import Data.List(unfoldr,intersperse) chop k | k>0 = unfoldr f where f [] = Nothing f s = Just $ splitAt k s main = do [k,s@(_:_)] <- getArgs let out = show . concat . intersperse " " res = chop (read k) s putStrLn $ "filter(/=' ')" ++ out res Typing: ./chop.hs 27 http://bkil.blogspot.com/2009/05/chopping-long-string-into-smaller-ones.html Gives: filter(/=' ')"http://bkil.blogspot.com/20 09/05/chopping-long-string- into-smaller-ones.html" Or if you prefer, you could alternatively opt for the following BASH routine: main(){ printf 'echo "' printf "$2"|sed -r "s~.{$1}~& ~g" echo '"|sed "s~ ~~g"' } This one...