【发布时间】:2016-07-25 08:54:15
【问题描述】:
我正在尝试从字符串中删除停用词,但问题是如果它再次出现在字符串中,它正在从单个单词中删除字符。
例如原始字符串是:
“这部电影不错。”
结果字符串是:
“这部电影不错。”。工作正常。但是
如果字符串是:“这部电影不错。”
那么结果字符串将是:“th movie good.”
由于 是 在此字符串中重复,因此它在结果中被排除。
另一个字符串:
“这款游戏太棒了。所以,我观看并玩了很多。”
结果:“gme fntstic。所以,我想拼多多。”
由于 a 在此字符串中重复,因此结果字符串显示所有排除 a 的单词。
我正在唱这个代码:
List<string> stopWordsList = new List<string>();
stopWordsList = stopWordsFilter();//funtion returning the list of stop words taking from file.
string propertyValue = "this game is fantastic. So, I watched and played a lot.";
foreach (string word1 in propertyValue.Split(' '))
{
foreach ( var word in stopWordsList)
{
if (word.Equals(word1) && word.Length == word1.Length)
{
propertyValue = propertyValue.Replace(word, "");
}
}
}
Console.WriteLine(propertyValue);
【问题讨论】:
标签: c# string stop-words