我有一个问题,我试图在字符串中搜索子字符串.该子字符串可能在字符串中,也可能不在字符串中.
str = "hello how are you?" substr = "how are"
我知道可以做的两种方式是:
string.indexOf("how are")
但是,还有其他"优化"方式吗?你会怎么做?
Ruby可以提供更好的答案吗?由于我们使用jRuby,答案可以是Ruby或Java.
ruby java string
java ×1
ruby ×1
string ×1