check if there is any of the chars inside the textbox

c#, string, winforms

Solution

You can do this to see if the string contains any of the letters:

private void button1_Click(object sender, EventArgs e)
{
    bool containsAnyLetter = letters.Any(c => textBox1.Text.Contains(c));
}

Or more simply:

private void button1_Click(object sender, EventArgs e)
{
    bool containsAnyLetter = textBox1.Text.IndexOfAny(letters) >= 0;
}

Problem

I have a chararray on global, button and textbox, how do I check if the word in textBox1.Text contains the letters in the chararray? ``` char[] letters = { 'a', 'e' }; private void button1_Click(object sender, EventArgs e) { bool containsAnyLetter = textBox1.Text.IndexOfAny(letters) >= 0; if (containsAnyLetter == true) { MessageBox.Show("your word contains a or e"); } } ```

Original source