jer*_*h91 14 c# regex linq linq-to-xml
我正在编写一个简短的C#来解析给定的XML文件.但是其中一个标记值可以更改,但在where子句中始终包含单词"快速启动"(忽略大小写和空格,但需要按相同的顺序排列).我不确定如何在C#中的sql语句中执行此操作.
var selected = from cli in doc.Descendants(xmlns+ "Result")
where cli.Element(xmlns + "ResultsLocation").Value == "Assessments-Fast-Startup"
select cli;
Run Code Online (Sandbox Code Playgroud)
Dav*_*ish 15
假设您正在寻找确切的字符串 - 您可以使用String.Contains
吗?
var selected = from cli in doc.Descendants(xmlns+ "Result")
where cli.Element(xmlns + "ResultsLocation").Value.Contains("Assessments-Fast-Startup")
select cli;
Run Code Online (Sandbox Code Playgroud)
否则,像:
var rx = new Regex("fast(.*?)startup", RegexOptions.IgnoreCase);
var selected = from cli in doc.Descendants(xmlns+ "Result")
where rx.IsMatch(cli.Element(xmlns + "ResultsLocation").Value)
select cli;
Run Code Online (Sandbox Code Playgroud)