How do I find if a string starts with another string in Ruby?

前端 未结 4 642
小鲜肉
小鲜肉 2020-12-13 08:02

What the best way to find if a string starts with another in Ruby (without rails)?

4条回答
  •  旧时难觅i
    2020-12-13 08:19

    puts 'abcdefg'.start_with?('abc')  #=> true
    

    [edit] This is something I didn't know before this question: start_with takes multiple arguments.

    'abcdefg'.start_with?( 'xyz', 'opq', 'ab')
    

提交回复
热议问题