This is what I have going on. I have a crawler that reads html, and i'm looking to know when it does not contain two strings. For example.
string firstString = "pineapple"
string secondString = "mango"
string compareString = "The wheels on the bus go round and round"
So basically I want to know when the first string and second string are not in the compareString.
Thanks for all the help!
This should do the trick for you.
For one word:
if (!string.Contains("One"))
For two words:
if (!(string.Contains("One") && string.Contains("Two")))
Option with a regexp if you want to discriminate between Mango
and Mangosteen
.
var reg = new Regex(@"\b(pineapple|mango)\b",
RegexOptions.IgnoreCase | RegexOptions.Multiline);
if (!reg.Match(compareString).Success)
...
bool isFirst = compareString.Contains(firstString);
bool isSecond = compareString.Contains(secondString );
So you can utilize short-circuiting:
bool containsBoth = compareString.Contains(firstString) &&
compareString.Contains(secondString);
Use Enumerable.Contains function:
var result =
!(compareString.Contains(firstString) || compareString.Contains(secondString));
Source: Stackoverflow.com