【发布时间】:2021-01-06 08:00:42
【问题描述】:
我有以下有效的代码,但想使用LINQ 对其进行编辑,以查找是否有任何Regex 搜索字符串在目标中。
foreach (Paragraph comment in
wordDoc.MainDocumentPart.Document.Body.Descendants<Paragraph>().Where<Paragraph>(comment => comment.InnerText.Contains("cmt")))
{
//print values
}
更准确地说,如果字符串以字母开头还是以符号开头- 或•,我必须通过LINQ 进行选择
这个Regex 适合我的情况吗?
string pattern = @"^[a-zA-Z-]+$";
Regex rg = new Regex(pattern);
有什么建议吗?
提前感谢您的帮助
【问题讨论】:
-
有一点不清楚:你有
comment => comment.InnerText.Contains("cmt"),它会在字符串中的任何地方获取包含cmt的项目,但是在your next question中你说字符串应该以cmt开头。是因为这些是针对不同场景的吗?