Compare strings with non-English characters?

后端 未结 7 2194
再見小時候
再見小時候 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:10

    Thanks to all who offered suggestions, but unfortunately they seem to be irrelevant. As it turns out Contains() has no problem with non-English characters at all. The problem was that the database field in question had html encoded text, so I needed to use HtmlDecode to compare the strings in the controller:

            if (vm.Description != "")
            {
                //HttpUtility.HtmlDecode needed because text in Description field is HtmlEncoded!
                consultants = consultants.Where(x => HttpUtility.HtmlDecode(x.Description).ContainsCaseInsensitive(vm.Description)).ToList();
            }
    

    I discovered this because the Contains() code worked fine when searching another field with non-English characters.

提交回复
热议问题