我需要检查,如果我的名单上的弦都在名单上的text to search
多少串被发现对比清单到字符串
这个发现是我要搜索的字符串
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley
of type and scrambled it to make a type specimen book.
这是我的名单
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the
printing and typesetting
industry. Lorem Ipsum has been the
industry's standard dummy
text ever since the 1500s, when
an unknown printer took a galley
我创建了一个示例代码
string longString = "word1, word2, word 3";
List<string> myList = new List<string>(new string[] { "word4", "word 2", "word 3" });
for (int i = 0; i < myList.Count; i++)
{
if (myList.Any(str => longString.Contains(str)))
{
Console.WriteLine("success!");
}
else
{
Console.WriteLine("fail!");
}
}
但它打印三次success
。它应该只有一次。我怎样才能做这项工作?我如何跳过已经用于搜索项目的项目。