方法:
public string ReplaceKeyWord(string content)
{
XinOChengCMS.BLL.KeyTableWord ktwBll = new XinOChengCMS.BLL.KeyTableWord();
DataTable dt = ktwBll.GetAllList().Tables[0];
string link = "";
for (int n = 0; n < dt.Rows.Count; n++)
{
link = link + "|" + dt.Rows[n]["KeyWord"].ToString();
}
string keyword1 = @"<(\ba\b)[^>]*>[\w\W]*?</\1 *>" + link;
return Regex.Replace(content, keyword1, ReplaceString, RegexOptions.IgnoreCase);
}
public string ReplaceString(Match m)
{
if (Regex.IsMatch(m.ToString(), @"<(\ba\b)[^>]*>[\w\W]*?</\1 *>", RegexOptions.IgnoreCase))
{
return m.ToString();
}
else
{
XinOChengCMS.BLL.KeyTableWord ktwBll = new XinOChengCMS.BLL.KeyTableWord();
DataTable dt = ktwBll.GetList("keyword='" + m.ToString() + "'").Tables[0];
if (dt.Rows.Count > 0)
return dt.Rows[0]["KeyPress"].ToString();
return "";
}
}
调用:
partModel.PartWord = new Title().ReplaceKeyWord(FCKeditor2.Value);//栏目内容加优化