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 = "how are"
Two ways which I know if can be done are:
string.indexOf("how are")- regex
But, is there any other “optimized” way? What would you have done?
Can Ruby provide a better answer? Since we use jRuby the answer can be in Ruby or Java.
In Ruby, use the
String#include?method:which returns
true.