Convert multiline textbox items to an array and then search for those items in another array
<p>I have a file containing lines of text which I've read into an array (search). I have a multiline text box the contents of which gets put into an array (lines) with a button click, what I'm trying to do is search the first array with each item from the 2nd array and add the found line to a listView. </p>

<p>I'm getting null for item in the foreach loop. I've tried swapping the foreach statement around with the lines and search arrays with no change.</p>

<p>More info, say the items.lst contains the following.</p>

<pre><code>Cats have four legs
Dogs have four legs
Horses have four legs
Elephants have four legs
</code></pre>

<p>In the multi line text box the user types Dogs and the next line Horses, what I want displayed in the list view when they press the button is: </p>

<pre><code>Dogs have four legs
Horses have four legs

    public Form1()
    {
        InitializeComponent();
        txtIndex.Text = @"c:\temp\items.lst";
        listView1.Columns.Add("Item", 100, HorizontalAlignment.Left);
    }

    private void btnSearch_Click(object sender, EventArgs e)
    {
        const string index = @"items.lst";
        string[] search = System.IO.File.ReadAllLines(index);
        string[] sep = {"\r\n"};
        string[] lines = txtList.Text.Split(sep, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in lines.Where(item =&gt; search.Contains(item)))
        {
            listView1.Items.Add(item + Environment.NewLine);
        }
    }
</code></pre>

<p>Thanks</p>

<p>6/6/2016
I ended up with the following which worked.</p>

<pre><code>private void btnSearch_Click(object sender, EventArgs e)
{
    const string index = @"items.lst";
    string[] search = System.IO.File.ReadAllLines(index);
    string[] sep = { "\r\n", "\n", "\r" };
    string[] lines = txtList.Text.Split(sep, StringSplitOptions.RemoveEmptyEntries);
    foreach (string line in search)
    {
        foreach (string item in lines)
        {
            if (line.Contains(item))
            {
                listView1.Items.Add(line + Environment.NewLine);
            }
        }
    }
 }
</code></pre>

<p>And LINQ version</p>

<pre><code>foreach (string line in from line in search from item in lines where line.Contains(item) select line)
        {
            listView1.Items.Add(line + Environment.NewLine);
        }
</code></pre>