Displaying Only the first x words of a string in rails

前端 未结 4 813
眼角桃花
眼角桃花 2020-12-31 08:47
<%= message.content %>

I can display a message like this, but in some situations I would like to display only the first 5 words of the st

4条回答
  •  伪装坚强ぢ
    2020-12-31 09:28

    Try the following:

    'this is a line of some words'.split[0..3].join(' ')
    => "this is a line" 
    

提交回复
热议问题