Как я могу найти (или получить) предложение по слову? - PullRequest
1 голос
/ 29 ноября 2011

У меня есть слово и текст. Я должен найти все предложения, которые имеют слово. У вас есть идеи?

piblic List<string> GetSnetences(string word)
{
    // search all proposals that have the word
{

Ответы [ 3 ]

5 голосов
/ 29 ноября 2011

Попробуйте сделать что-то вроде этого:

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();
}

В конце совпадения будут перечислением, содержащим все предложения, содержащие слово, которое вы ищете.

1 голос
/ 29 ноября 2011
piblic List<string> GetSnetences(string word)
{
   string text = "Here is some text. It has some sentences. There are a few sentences.";
   List<string> results = text.Split(".");
   return results.FindAll(delegate(string str) { return str.ToLower() == word.ToLower(); });
}

Вы можете попробовать это.

0 голосов
/ 29 ноября 2011

Вы можете использовать метод contains () строки, чтобы узнать, содержит ли строка несколько букв или слов.

...