Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- str = "many words here words words words ..."
- first_500_words = str.split(" ").first(500).join(" ")
- first_500_chars = str[0..500]
- def truncate_words(text, length = 300, end_string = ' …')
- words = text.split()
- words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
- end
- str = "this is really long string which I want to truncate..."
- str.truncate 300, separator: " "
- str.truncate(300, separator: " ")
- str.split.first(300).join " "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement