I want to check if a string contains all the values stored in a list; Therefore, it will only give you the “correct answer” if you have all the “keywords” from the list in your answer. Heres something I'm tired that half fails (doesn't check all arrays, only one will accept). The code is tired:
foreach (String s in KeyWords) { if (textBox1.Text.Contains(s)) { correct += 1; MessageBox.Show("Correct!"); LoadUp(); } else { incorrect += 1; MessageBox.Show("Incorrect."); LoadUp(); } }
Essentially, I want:
Question: What is the definition of psychology?
Keywords in arraylist: research, mental process, behavior, people
Answer: Psychology is a study of the mental process and behavior of people.
Now, if ONLY if the answer above contains all the keywords, my code will accept the answer. Hope I figured it out.
Edit: Thank you all for your help. All replies were rejected, and I thank everyone for the prompt replies. I voted for the answer, which can be easily adapted to any code. :)
c #
Metab
source share