[Haskell-cafe] split string into n parts

Udo Stenzel u.stenzel at web.de
Mon Oct 23 17:39:00 EDT 2006

jim burton wrote:
> I want to split a string into 5 parts of equal length, with the last fifth
> padded if necessary, but can't get it right - here's what I've got - 

fifths s = unwords.take 5.unfoldr (Just . splitAt l) $ s ++ repeat ' '
  where l = (length s + 4) `div` 5 

Of course no Haskeller in his right mind would carelessly apply the
final 'unwords' unless this was for immediate output.

The Second Law of Thermodynamics:
        If you think things are in a mess now, just wait!
	                -- Jim Warner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061023/7955a415/attachment.bin

More information about the Haskell-Cafe mailing list