[UWP] [win 10 phone] [C#]在列表中搜索特定内容是否区分大小写 [英] [UWP][win 10 phone][C#]searching the list for a particular content whether it is case sensitive or not
问题描述
大家好,
在我的应用程序中我有搜索功能,我实现如下
Hello all,
In my application iam having a search functionality , and i implemented it like below
placelist = placelist.Where(i => i.category_name.Contains(postData)).Union(placelist.Where(i => i.category_address.Contains(postData))).Union(placelist.Where(i => i.category_tags.Contains(postData))).ToList();
eventlist = eventlist.Where(i => i.event_name.Contains(searchconte)).Union(eventlist.Where(i=>i.event_location.Contains(searchconte))).ToList();
indexlist = indexlist.Where(i => i.restaurant_location.Contains(searchtext)).Union(indexlist.Where(i => i.restaurant_name.Contains(searchtext))).Union(indexlist.Where(i=>i.cuisine_type.Contains(searchtext))).Union(indexlist.Where(i=>i.special_dishes.Contains(searchtext))).ToList();
当iam输入postData为bamb时,它什么也没有返回,但是当我输入像Bamb这样的东西时,它会显示结果。
它只搜索区分大小写,我想修改这个语句,它应该搜索并返回内容,无论它是否区分大小写,还应该为具有昏迷的内容( ,)冒号(:),引号(,'')
如何修改语句以获得上述功能。
我的尝试:
when iam Entering the postData as "bamb", it is returning nothing , But when i enter the same thing like "Bamb", It is showing the results.
It is searching only Case-Sensitive, I want modify this statement in such a way that it should search and return the content whether it is Case-sensitive or not, and also it should for the content with coma(,) colon(:),Quotes("",'')
How can i modify the statement to get the above mentioned functionality.
What I have tried:
placelist = placelist.Where(i => i.category_name.Contains(postData)).Union(placelist.Where(i => i.category_address.Contains(postData))).Union(placelist.Where(i => i.category_tags.Contains(postData))).ToList();
eventlist = eventlist.Where(i => i.event_name.Contains(searchconte)).Union(eventlist.Where(i=>i.event_location.Contains(searchconte))).ToList();
indexlist = indexlist.Where(i => i.restaurant_location.Contains(searchtext)).Union(indexlist.Where(i => i.restaurant_name.Contains(searchtext))).Union(indexlist.Where(i=>i.cuisine_type.Contains(searchtext))).Union(indexlist.Where(i=>i.special_dishes.Contains(searchtext))).ToList();
推荐答案
当iam进入postData时作为bamb,它什么都没有返回,但是当我输入像Bamb这样的东西时,它显示的是结果。
when iam Entering the postData as "bamb", it is returning nothing , But when i enter the same thing like "Bamb", It is showing the results.
问题相当经典且容易解决。
你有一些数据(无论组织是什么)。
出于性能考虑,你已经用一对夫妇(关键,位置)索引了数据。 />
诀窍是对大写(键)进行索引并对大写(搜索键)进行所有搜索。只要在索引和搜索上完成相同的操作,它也可以使用小写()。
The problem is rather classical and easy to solve.
You have some data (whatever is the the organization).
For performance considerations, you have indexed the data with some couples (key, position).
The trick is to index on uppercase(key) and to do all searches on uppercase(searched key). It works also with lowercase() as long as the same is done on index and searches.
我修改了下面的代码,如下所示:StackOverflow
I have modified the code as below referred from StackOverflow
indexlist = (from item in indexlist
where ContainsIgnoreCase(item.restaurant_location,searchtext)
|| ContainsIgnoreCase(item.restaurant_name, searchtext)
|| ContainsIgnoreCase(item.cuisine_type, searchtext)
|| ContainsIgnoreCase(item.special_dishes, searchtext)
select item).ToList();
placelist = (from item in placelist
where ContainsIgnoreCase(item.category_name, postData)
|| ContainsIgnoreCase(item.category_tags, postData)
|| ContainsIgnoreCase(item.category_address, postData)
select item).ToList();
eventlist = (from item in eventlist
where ContainsIgnoreCase(item.event_name, searchconte)
|| ContainsIgnoreCase(item.event_location, searchconte)
select item).ToList();
othersList = (from item in othersList
where ContainsIgnoreCase(item.category_name, PostData)
|| ContainsIgnoreCase(item.category_tags, PostData)
|| ContainsIgnoreCase(item.category_address, PostData)
select item).ToList();
修改对我有用,
感谢您试用我的问题。
This modification worked for me,
Thank You for trying out my problem.
这篇关于[UWP] [win 10 phone] [C#]在列表中搜索特定内容是否区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!