Rails breakup long lines


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.