string str = "cat:fox";
string[] strArr = new string[] { "cat", "dog" };
I have a string like str. I need to check whether that string contains any element present in the strArr like exactly "cat" or "dog".
If the string is "cat:fox" method should returns true. If the string is "dog:fox" method should returns true.
The thing I tried was:
string[] split = str.Split(':');
blnReturn = false;
foreach (var item in split)
{
foreach(var item1 in strArr)
{
if(item == item1)
blnReturn = true;
}
}
Note :- Meaning is values are concatenated with colon.I need to check whether that string contains any value present in the strArr.
How to do this better?
UPDATE
Requirement is if str is str = "cat dfgfg:fox"; It should not return true.
Only it should be cat.
Otherwise we can check this way strData = str.Split(':');
and strArr is already there.
Condition is any one data in strArr (string array) should match with strData (string array) then it should return true.