在段落中查找特定关键字

时间:2015-12-10 21:20:48

标签: c# console-application

我试过这个,但它与数组中的字符串不匹配 注意。我不想使用正则表达式。

string pgraph = ("i love zaiby and zaiby is my best friend");
string word = ("zaiby");
string[] singleword = pgraph.Split();
bool findword = singleword.Equals(word);

if (findword == true)
{
    Console.Write("keyword founded");
}
else
{
    Console.Write("keyword not founded");
}

1 个答案:

答案 0 :(得分:2)

您正在将字符串数组与字符串进行比较 请尝试使用以下行代替singleword.Equals行:

bool findword = singleword.Any(w => w.Equals(word));