Truncate string with Rails?

前端 未结 7 635
醉酒成梦
醉酒成梦 2021-01-31 07:40

I want to truncate a string as follows:

input:

string = \"abcd asfsa sadfsaf safsdaf aaaaaaaaaa aaaaaaaaaa ffffdffffdffffdffffddd\"
相关标签:
7条回答
  • 2021-01-31 08:08

    You can do almost the same without Rails:

    text.gsub(/^(.{50,}?).*$/m,'\1...')
    

    50 is the length you need.

    0 讨论(0)
提交回复
热议问题