I have some strings:
"rose with ribbon"
"roses in concrete"
"roses on bed"
I have to write a program to find string where preffered word exists
E.g: find string where "on" is, so I need to get only "roses on bed".
I used this code:
foreach (KeyWord key in cKeyWords)
{
foreach (string word in userWords)
{
if (key.keyWord.IndexOf(word) != -1)
{
ckeyList.Add(key);
}
}
}
but I get all strings because IndexOf finds "on" in all of them.
Is there any other solution to find separate word in string without splitting? Maybe it is possible to use Linq or Regex? but I'm not good at using them so would be nice to have any examples.
IndexOf()
. – Overslaughvar linesWithOn=from c in cKeyWords where c.Split(' ').Contains("on") select c;
– Unique