首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >用于从句子中获取单词的Linq

用于从句子中获取单词的Linq
EN

Stack Overflow用户
提问于 2019-06-03 19:28:06
回答 3查看 902关注 0票数 4

我有一个单词列表和一个句子列表。我想知道在which 中可以找到哪些句子。

下面是我的代码:

代码语言:javascript
复制
List<string> sentences = new List<string>();
List<string> words = new List<string>();

sentences.Add("Gallia est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.");
sentences.Add("Alea iacta est.");
sentences.Add("Libenter homines id, quod volunt, credunt.");

words.Add("est");
words.Add("homines");

List<string> myResults = sentences
  .Where(sentence => words
     .Any(word => sentence.Contains(word)))
  .ToList();

我需要的是一个元组列表。在句子中找到的句子和单词。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56426412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档