Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. str = "many words here words words words ..."
  2. first_500_words = str.split(" ").first(500).join(" ")
  3. first_500_chars = str[0..500]
  4.  
  5. def truncate_words(text, length = 300, end_string = ' …')
  6. words = text.split()
  7. words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
  8. end
  9.  
  10. str = "this is really long string which I want to truncate..."
  11.  
  12. str.truncate 300, separator: " "
  13.  
  14. str.truncate(300, separator: " ")
  15.  
  16. str.split.first(300).join " "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement