How to get a substring of text?

前端 未结 5 1784
无人及你
无人及你 2020-12-02 14:48

I have text with length ~700. How do I get only ~30 of its first characters?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 15:42

    if you need it in rails you can use first (source code)

    '1234567890'.first(5) # => "12345"
    

    there is also last (source code)

    '1234567890'.last(2) # => "90"
    

    alternatively check from/to (source code):

    "hello".from(1).to(-2) # => "ell"
    

提交回复
热议问题