Posted By

gdonald on 09/27/06


Tagged

breakup long lines


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


Rails breakup long lines


 / Published in: Ruby
 

  1. def break_up_long_line(str, max)
  2. counter = 0
  3. new_text = ''
  4. for i in 0...str.length
  5. if str[i,1] =~ /\n/
  6. counter = 0
  7. else
  8. counter = counter + 1
  9. end
  10. new_text << str[i,1]
  11. if counter >= max && str[i,1] =~ /\s/
  12. new_text << "\n"
  13. counter = 0
  14. end
  15. end
  16. new_text
  17. end

Report this snippet  

You need to login to post a comment.