File name from a txt and files. Is there a difference in comparison?

1

I created a list of 13 file names, which I extracted using GetFileName (). Other list I broke a txt file and loaded those names into another list. So I have this:

ListaNomeArquivo

ListaNomeTxt

I need to get the name of the ListItemList list and see if it exists inside the ListItemTxt. Both Contains and Equals, always returns different and I have the same names. Just to give an example. I have in both lists that name:

web\ace\asp\ace0003a.asp

It turns out that the lambda I did, says they are different:

 var busca = listaCommiter.Where(l => !l.Contains(listaFarm.ToString()));

How do I just store what does not really exist?

The complete code for this routine:

private List<string> ComparaArquivo()
        {
            List<string> listaCommiter = new List<string>();
            List<string> listaFarm = new List<string>();
            List<string> listaDiferenca = new List<string>();

            try
            {
                listaCommiter = _listaCommiter();
                listaFarm = _listaFarm();

                var busca = listaCommiter.Where(l => !l.Contains(listaFarm.ToString()));                

                return listaDiferenca;
            }
            catch(Exception ex)
            {
                string r = ex.Message;
                return null;
            }

        }

The list in return listaDiferenca; is returning nothing, because I'm still developing. It will return busca .

    
asked by anonymous 01.03.2016 / 19:50

2 answers

1

To return only what you have in listaFarm but is not in listaCommiter , just reformulate your query:

var diferenca = listaCommiter.Where(l => !listaFarm.Contains(l));

You can also use Enumerable.Except<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

var diferenca = listaCommiter.Except(listaFarm);

If you still want only what is common between the two, you can use Enumerable.Intersect<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

var comum = listaCommiter.Intersect(listaFarm);

I hope I have helped \ o /

    
31.05.2016 / 19:36
1

For this case, use Except . :

var busca = listaCommiter.Except(listaFarm);

It will return in search , all of listaCommiter that does not exist in listaFarm .

    
31.05.2016 / 17:56