I have a string variable with content:
varMessage =
\"hi/thsid/sdfhsjdf/dfjsd/sdjfsdn\\n\"
\"/my/name/is/balaji.so\\n\"
A more succinct idiom than the accepted answer above that's available in Rails (from 3.1.0 and above) is .in?
:
my_string = "abcdefg"
if "cde".in? my_string
puts "'cde' is in the String."
puts "i.e. String includes 'cde'"
end
I also think it's more readable.
See the in? documentation for more information.
Note again that it's only available in Rails, and not pure Ruby.