提问人:krishna mohan 提问时间:10/30/2023 最后编辑:krishna mohan 更新时间:10/30/2023 访问量:53
如何避免与 c 中列表数组元素中的字符串匹配#
How to avoid matching the string from the list array element in c#
问:
如何避免匹配 c#.its 中列表数组元素中的字符串失败,因为紧急:否
示例数据
Urgent: 否 //不应匹配 Urgent 是 //应匹配 //abc
Urgent xyz //应匹配
法典
private static readonly HashSet<string> urgentKeywords = new(StringComparer.OrdinalIgnoreCase)
{
"Urgent","FAST"
};
private static readonly List<string> nonUrgentKeywords = new List<string>()
{
"Urgent: No"
};
var extractedUrgentText = data
.Where(item => "urgent".Equals(item.Name, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(item.Value))
.Where(item => Regex
.Matches(item.Value, @"\p{L}+")
.Cast<Match>()
.Any(match => urgentKeywords.Contains(match.Value)))
.Where(item => item.Value != nonUrgentKeywords ) //not working this where clause
.ToArray().Count();
答: 暂无答案
评论
.Skip(1)
"urgent"
Where
ToArray()
Count