Question

I want to parse the content of my text_box to verify if my text contain each words of my textbox.

var answer = listanswer.Where(x => x.description.Contains(TextBox_1.Text));

if (answer.Count() == 1)
{
    Interaction question = answer.First();
    foreach (Choice choice in question.choices)
    {
        if (choice.status == "correct")
        {
            lb_input.Items.Add(choice.text);
        }
    }
}

Actually I check the total content of my text_box, I'm looking for a way to verify each words.

Any ideas ?

Was it helpful?

Solution

You need to split the text by white-space, then you can use Enumerable.All:

string[] words = TextBox_1.Text.Split();
var answer = listanswer.Where(x => words.All(w => x.description.Contains(w)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top