Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:06:57+00:00 2026-05-26T05:06:57+00:00

Just to avoid confusion I am talking about linq to object and nothing else.

  • 0

Just to avoid confusion I am talking about linq to object and nothing else.
I am working with lots objects in memory and I need to filter them.
we have a screen with lots of options where a user can select many values.

I need to implement something similar to the “Like” operator in sql.
I did found a post about it in this site and uses regex but I have never used it.
I want to know if my string pattern is correct.Should not use “%” “%”?

I have also read that you should use a combination of startWith -endWith and contains,but I have not found any examples that uses all the them combined,just to get a feel how to do it.

I do something like this

string pattern = string.Format(".*{0}.*", criteria.SearchText);
myList= myList.Where(x => x.Message.Like(pattern)).ToList();

public static bool Like(this string s, string pattern, RegexOptions options = RegexOptions.IgnoreCase)
{
    return Regex.IsMatch(s, pattern, options);
}

Any suggestions

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:06:57+00:00Added an answer on May 26, 2026 at 5:06 am

    If you want to check if a string contains another you can use:

    myList = myList.Where(x => x.Message.Contains(criteria.SearchText)).ToList();
    

    or

    myList = myList.Where(x => x.Message.IndexOf(criteria.SearchText) != -1).ToList();
    

    (the second variant is good because with IndexOf you can specify the CultureInfo)

    If you want to mix a user-defined word in a Regex you should use the Regex.Escape() to escape it, so that if the user writes a*, the searched text is a* instead of any number of a.

    string pattern = string.Format(".*{0}.*", Regex.Escape(criteria.SearchText));
    

    But note that as written, it’s equivalent to:

    string pattern = string.Format("{0}", Regex.Escape(criteria.SearchText));
    

    because you haven’t put anchors to your regex, so the regex will be searched anywhere in the string.

    If you want to anchor the user-defined word, so for example you want to search for words that begin with

    string pattern = string.Format("^{0}", Regex.Escape(criteria.SearchText));
    

    or end with

    string pattern = string.Format("{0}$", Regex.Escape(criteria.SearchText));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just an academical question: Is it possible to avoid int casting when comparing Enum
I just started with Spring Web MVC. I'm trying to avoid file extenstions in
I'm using GDI+ in a C++/MFC application and I just can't seem to avoid
Just what the title says, I need to change the password for an existing
Just bought a 2.4GHz Intel Core 2 Duo iMac with 2GB of memory and
a JTabbedPane is just what I need for my purpose. I have very limited
Just looking for the first step basic solution here that keeps the honest people
just a quick question: I am a CS undergrad and have only had experience
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.
Just how much slower are events? I have written a streaming XML parser (that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.