2013-02-17 39 views
0

我写代码:如何搜索和查找字(以大写或小写字符不敏感)

string strSearch = textBox1.Text; 
XDocument xdoc; 
List<string> lstItemsForAdd; 
lstItemsForAdd = xdoc.Descendants("name") 
         .Where(item => item.Value.Contains(strSearch)) 
         .Select(item => item.Value) 
         .Take(5) 
         .OrderBy(item => item) 
         .ToList(); 

下面这段代码是为找到......
上下性格灵敏度我该如何搜索没有敏感的上下字符
但我不想转换项目和strSearch更低/高字符
所以我该怎么办?

感谢和亲切的问候。

+0

检查StringComparison.OrdinalIgnoreCase – Mate 2013-02-17 05:49:59

+0

'@ Mate'我尝试从'StringComparison.OrdinalIgnoreCase'使用,但在此代码不能使用!我可以用吗 ?怎么样 ? – 2013-02-17 05:52:05

+0

我已经添加了一个例子的答案。我希望这会有所帮助 – Mate 2013-02-17 06:04:16

回答

0

试试这个

string strSearch = textBox1.Text; 
XDocument xdoc; 
List<string> lstItemsForAdd; 
lstItemsForAdd = xdoc.Descendants("name") 
         .Where(item => item.Value.IndexOf(strSearch. StringComparison.OrdinalIgnoreCase) >= 0) 
         .Select(item => item.Value) 
         .Take(5) 
         .OrderBy(item => item) 
         .ToList(); 
相关问题