You must Sign In to post a response.
  • Category: LINQ

    I need a Linq Query to search a string

    Hi All,
    I got one One requirement ,that is search a string
    Example :
    searchPharse: Pain,Abdominal Diabetes
    result should be displayed with pain related recors ,Abdominal related records and Diabetes related records
    Please suggest
  • #764968
    Hi Prasad,

    Please try with the below LINQ.
    Assume you have all records in MedicalList List.

    List<string> selectedList= MedicalList.Select(records => (recordname.contains("pain") ||
    recordname.contains("abdominal") ||
    recordname.contains("diabetes ")).ToList();

    Here selectedList will display the records what you expected.

    Please try and let me know.

    Prabu Thangavelu
    Follow me:

  • #764972
    You can use "Contains" for compare the string inside of the collection. You can select the using "Any". Followings is the sample Linq

    public bool ContainsAny(string SearchText, IEnumerable<string> searchTerms)
    return searchItems.Any(searchItem => SearchText.ToLower().Contains(searchItem .ToLower()));

    You have another obtion also for "FindAll" and "ContainsAny". Following is the sample code

    List<string> foundUsers = allUsers.FindAll(s => s.ContainsAny(searchString));

    By Nathan
    Direction is important than speed

  • Sign In to post your comments