none
Check if a string contains all the strings from a list RRS feed

  • Question

  • Hi,

    Is there a linq function to check if a string contains all the items from the list of strings?

    e.g. my table contains the following records:

    "The quick brown fox"

    "The big brown bear"

    "The big red fox"

     

    if the list<string> has 2 items: "big" and "bear", the function should give me "The big brown bear".

    if the list<string> has 2 items: "The" and "brown", the function should give me "The quick brown fox" and "The big brown bear".

     

    Currently, i loop through the records to achieve the result I need but I was thinking that maybe there's a function like ContainsAny.

    Hope my question is clear.

     

    Thanks!

    Dhon

     

     

     


    Dhon Nuevo
    Wednesday, May 11, 2011 9:57 AM

Answers

  • Hi,

    Here you have a sample to find if a string any items of a list of words. You can do the same with All method, but there is only for comparing only one string. So with a list os ftring, I think there is no another way than iterate through the records.

    In any case, you could encapsulate your own ContainsAny method as an extension.

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    Wednesday, May 11, 2011 11:28 AM