1

I have a keyword Person. I have a list that has elements inside such as Person A,Apple, Person B,Pear , Person C ,Banana

I am trying to get the elements in the list that contains the keyword .

for(int i =0; i < list.items.count; i++){
   if (keyword == list[i])
      Console.WriteLine("Person")
}

Im trying the code above and it does not seem to work. Can anyone help?

Pio
  • 513
  • 4
  • 19
shikiko
  • 162
  • 1
  • 7
  • 4
    Change `if (keyword == list[i])` to `if (list[i].Contains(keyword))` – praty Oct 25 '17 at 10:06
  • 1
    I understand that `Person A` is considered as `Person`. What about `Personal`? I'm guessing that should not be considered as `Person`. The easy way to do a comparison like that is with regular expressions. – Zohar Peled Oct 25 '17 at 10:12
  • 1
    @praty that would also pass things like `Personal`. I'm guessing that should not pass. – Zohar Peled Oct 25 '17 at 10:12
  • I don't 100% agree with the duplicate, but it should be enough to answer the question (therefore no reopen vote from me). The title contradicts the actual question *"I am trying to get the elements in the list that contains the keyword ."* a bit. – Manfred Radlwimmer Oct 25 '17 at 10:14
  • It's not a duplicate, since the other question is looking for a simple contains, while this one is looking for containing a **word**.However, the accepted answer to that question does raise an important detail about case insensitivity I'm not sure a lot of people are even aware of. – Zohar Peled Oct 25 '17 at 10:24

0 Answers0