I have str='My long string with this text'
I know about truncate str, length: 20, omission: ''
,but it cuts words
My goal is to keep full word after truncation. Is it possible?
string can be random length
I have str='My long string with this text'
I know about truncate str, length: 20, omission: ''
,but it cuts words
My goal is to keep full word after truncation. Is it possible?
string can be random length
As per documentation:
truncate("Once upon a time in a world far far away", length: 17)
# => "Once upon a ti"
truncate("Once upon a time in a world far far away", length: 17, separator: ' ')
# => "Once upon a"
Please find more on this in the following SO link:
Truncate a string without cut in the middle of a word in rails