Compare strings with non-English characters?

后端 未结 7 2121
再見小時候
再見小時候 2021-01-19 07:20

I need to compare strings for a search mechanism on a web site. I use C#. I tried two ways:

consultants.Where(x => 
    x.Description.ToLower().Contains(v         


        
7条回答
  •  旧巷少年郎
    2021-01-19 08:11

    Indexing is a big part of searching. I think you would be best served by using something ready and solid, like Lucene or Solr.

    If you still insist on searching using regexes on non-ascii characters, you should probably learn more on unicode categories and then use them to strip any accent marks (for example, strip with \p{P} or \p{M}) before searching for that word in the text.

    Note: You will also probably need to normalize your strings using the FormC flag in order to decompose and strip/search more effectively

提交回复
热议问题