我试图将一长串文本截断为一定长度,但也希望确保截断的结果以空白结尾.之后我还要加上一个省略号.
例如:
"This is a very long string that has more characters than I want in it."
变成这样:
"This is a very long string that..."
我从这里开始,但很明显,这并不能解决在空白处结束字符串的问题.
<%= item.description[0..30] %>…