Best way to find a substring in a string
java, ruby, string
Solution
In Ruby, use the `String#include?` method:
str = "hello how are you?"
substr = "how are"
str.include? substr
which returns `true`.
Problem
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.