Truncate string to the first n words

前端 未结 4 1675
有刺的猬
有刺的猬 2020-12-28 14:16

What\'s the best way to truncate a string to the first n words?

4条回答
  •  遥遥无期
    2020-12-28 14:54

    This could be following if it's from rails 4.2 (which has truncate_words)

    string_given.squish.truncate_words(number_given, omission: "")
    

提交回复
热议问题