c# - 我如何逐字搜索(或获取)句子?

标签 c# string search

我有一个词和文本。我必须找到所有包含该词的提案。 你有什么想法吗?

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/

相关文章:

c# - 您应该如何处理存储库模式中的父实体和子实体?

c# - 如何将 json 反序列化为结构体?

C#密码生成器,生成多个密码

Java - 从字符串中提取html信息

Swift - 我应该创建字符串 "count"的局部变量吗?

Java算法String-ID-生成分层父子

java - 搜索 200 k 整数数组的数组? java

c# - 如何在 MVC 中保护文档/pdf 请求的安全?

Mysql:从所有表中获取结果

android - 搜索 ListView 标志的功能 - 无法解析方法“getFilter()”