How to check whether a string contains a substring in Ruby

后端 未结 9 988
南旧
南旧 2020-11-28 18:02

I have a string variable with content:

varMessage =   
            \"hi/thsid/sdfhsjdf/dfjsd/sdjfsdn\\n\"


            \"/my/name/is/balaji.so\\n\"
                 


        
9条回答
  •  难免孤独
    2020-11-28 18:12

    You can use the include? method:

    my_string = "abcdefg"
    if my_string.include? "cde"
       puts "String includes 'cde'"
    end
    

提交回复
热议问题