How to check whether a string contains a substring in Ruby

后端 未结 9 986
南旧
南旧 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:08

    If case is irrelevant, then a case-insensitive regular expression is a good solution:

    'aBcDe' =~ /bcd/i  # evaluates as true
    

    This will also work for multi-line strings.

    See Ruby's Regexp class for more information.

提交回复
热议问题