I want to write a condition that evaluates to tru开发者_开发百科e if a string contains the phrase: "no row at position 0".
For example, let's assume the string is:
"Feed returned error status: There is no row at position 0."
You don't need a regular expression to look for a fixed substring, just include?
will do:
"Feed returned error status: There is no row at position 0.".include?("no row at position 0")
# => true
For this specific case, you don't need a regex. A simple index
will do:
irb(main):001:0> a = "Feed returned error status: There is no row at position 0."
=> "Feed returned error status: There is no row at position 0."
irb(main):002:0> a.index("no row at position 0")
=> 37
index
will return nil
if it didn't find the string:
irb(main):003:0> a.index("no row at position 0a")
=> nil
精彩评论