【问题标题】:Searching in xml with linq使用 linq 在 xml 中搜索
【发布时间】:2009-10-20 22:20:10
【问题描述】:

我想在 xml 文件中进行搜索。这是我的 linq 语句。

string _sSemptom  = "try";
XElement xe =  from c in xdSemptom.Elements().Elements().Elements()
                         .Elements().Attributes("Isim")
               where c.Value.Length >= _sSemptom.Length &&
                     c.Value.Contains(_sSemptom)
               select c.Parent

我可以通过这种方式找到 XElement,但如果 _sSemptom 是“Try”,我就找不到它。如何使用大小写变体进行搜索?

感谢您的帮助。

【问题讨论】:

    标签: c# xml linq linq-to-xml


    【解决方案1】:

    编辑:实际上,Contains() 没有 StringComparison 重载。您可以改用IndexOf()

    c.Value.IndexOf(_sSemptom, StringComparison.OrdinalIgnoreCase) > -1
    

    【讨论】:

      猜你喜欢
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-03
      • 1970-01-01
      相关资源
      最近更新 更多