Truncate Text With Word Boundaries In Ruby
Join the DZone community and get the full member experience.
Join For Free
def truncate_words(text, length = 30, end_string = ' …')
words = text.split()
words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
end
Truncate (SQL)
Opinions expressed by DZone contributors are their own.
Comments