【问题标题】:How to Search and find Word ( No sensitivity to upper or lower character )如何搜索和查找单词(对大小写不敏感)
【发布时间】:2013-02-01 19:46:12
【问题描述】:

我写了一段代码:

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();

现在这段代码对 find 的大小写敏感......
如何在不区分大小写字符的情况下进行搜索
但我不想将项目和 strSearch 转换为小写/大写字符
那我该怎么办?

感谢和亲切的问候。

【问题讨论】:

  • 检查 StringComparison.OrdinalIgnoreCase
  • @Mate 我尝试从StringComparison.OrdinalIgnoreCase 使用,但在此代码中无法使用!我可以用吗 ?怎么样?
  • 我添加了一个带有示例的答案。我希望它会有所帮助

标签: c# search character uppercase lowercase


【解决方案1】:

试试这个

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();

【讨论】:

    猜你喜欢
    • 2019-12-27
    • 2017-02-21
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多