On 10/23/06, jim burton <<a href="mailto:jim@sdf-eu.org">jim@sdf-eu.org</a>> wrote:<br>> <br>> I want to split a string into 5 parts of equal length, with the last fifth<br>> padded if necessary, but can't get it right
<br><br>I got this:<br><br>fifths :: String -> String<br>fifths xs = let len = (length xs + 4) `div` 5<br> padded = take (len * 5) (xs ++ " ")<br> in unwords $ nth len padded
<br> where nth _ [] = []<br> nth n xs = (take n xs) : (nth n $ drop n xs)<br><br>> *Main> fifths "IDOLIKETOBEBESIDETHESEASIDE"<br>> "IDOLI KETOBE BESIDE THESEA SIDEXX"<br>> *Main> fifths "12345"
<br>> "1 23 45"<br><br>This gives the following results:<br><br>"IDOLIK ETOBEB ESIDET HESEAS IDE "<br><br>and<br><br>"1 2 3 4 5"<br><br>But it also gives this result, which may or may not be correct for your problem:
<br><br>*Main> fifths "123456"<br>"12 34 56 "<br><br>-- <br>Rich<br><br>AIM : rnezzy<br>ICQ : 174908475<br>