我有一个单词和文字。我必须找到所有提出这个词的提案。 你有什么想法吗?
piblic List<string> GetSnetences(string word)
{
// search all proposals that have the word
{
答案 0 :(得分:5)
尝试做这样的事情:
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 :(得分:1)
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(); });
}
你可以尝试这个。
答案 2 :(得分:-2)
你可以使用字符串的contains()方法来查明一个字符串是否包含一些字母o。