我正在编写一个简短的 C# 来解析给定的 XML 文件。但是其中 1 个标记值可以更改,但始终在 where 子句中包含单词“Fast Start up”(不考虑大小写和空格,但需要顺序相同)。我不确定如何在 C# 中的类似 sql 的语句中执行此操作。
var selected = from cli in doc.Descendants(xmlns+ "Result")
where cli.Element(xmlns + "ResultsLocation").Value == "Assessments-Fast-Startup"
select cli;
最佳答案
假设您正在寻找确切的字符串 - 您可以只使用 String.Contains
吗?
var selected = from cli in doc.Descendants(xmlns+ "Result")
where cli.Element(xmlns + "ResultsLocation").Value.Contains("Assessments-Fast-Startup")
select cli;
否则,类似于:
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;
关于c# - Linq 语句中的正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16922818/