Best way to find a substring in a string

后端 未结 7 1375
北荒
北荒 2020-12-11 16:32

I have a problem where I am trying to search for a substring in string. That substring may or may not be in the string.

str = \"hello how are you?\"
substr =         


        
7条回答
  •  鱼传尺愫
    2020-12-11 16:58

    In Ruby, use the String#include? method:

    str = "hello how are you?"
    substr = "how are"
    str.include? substr 
    

    which returns true.

提交回复
热议问题