我有一个词和文本。我必须找到所有包含该词的提案。 你有什么想法吗?
piblic List<string> GetSnetences(string word)
{
// search all proposals that have the word
{
最佳答案
尝试做这样的事情:
var text =
"Here is some text. It has some sentences. There are a few sentences.";
var word = "SOME";
public List<String> GetSentences(String text, String word) {
var sentences =
text.Split(new[] { ". " }, StringSplitOptions.RemoveEmptyEntries);
var matches = from sentence in sentences
where sentence.ToLower().Contains(word.ToLower())
select sentence;
return matches.ToList();
}
最后,匹配项将是一个枚举,其中包含包含您要搜索的词的所有句子。
关于c# - 我如何逐字搜索(或获取)句子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8314944/