日期:2014-05-18 浏览次数:21014 次
public bool find(string keywords, string text)
{
List<string> incList = new List<string>();
List<string> excList = new List<string>();
if (keywords.IndexOf("-") > -1)
{
string incKeys = keywords.Substring(0, keywords.IndexOf("-"));
string excKeys = keywords.Substring(keywords.IndexOf("-") + 1);
if (keywords.IndexOf("+") > -1)
{
if (incKeys.IndexOf("+") > -1)
incList = new List<string>(incKeys.Split('+'));
else
incList.Add(incKeys);
}
if (excKeys.IndexOf("-") > -1)
excList = new List<string>(excKeys.Split('-'));
else
excList.Add(excKeys);
}
else
{
if (keywords.IndexOf("+") > -1)
incList = new List<string>(keywords.Split('+'));
else
incList.Add(keywords);
}
if (incList.Count > 0)
{
foreach (string s in incList)
{
if (text.IndexOf(s) == -1)
return false;
}
}
if (excList.Count > 0)
{
foreach (string s in excList)
{
if (text.IndexOf(s) > -1)
return false;
}
}
return true;
}
------解决方案--------------------
路过