2013-02-17 65 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();