在发帖子的时候对帖子的内容判断,如果帖子中有关键字,则不让发货替换掉,有没有例子啊?
解决方案 »
- .net做的网站是不是一定要先编译
- 请教:怎么让TextBox内的文本居中
- datagrid中的radiobuttonlist 列选中某向后,怎么取消(即一项都不选中)
- 发了200分,还有放分帖,找中英文文章
- 关于中国式网站
- 请大家帮忙看看!关于Asp在线考试系统的计时问题,到时间后自动交卷
- 编译器错误信息??????????
- 悬赏分
- 能否简单介绍以下ms 的 petshop中的component 和 inc 目录下的文件,还有整个结构!欢迎大家讨论讨论!!
- 能不能给解释一下.NET /C#/Web Services/.NET Framework都是什么意思啊?什么联系?谢谢
- 网站被挂马 求助
- 递归方法(这种怎么用递归啊!)
遍历关键词表查询是否有关键词
for循环开始
if(s.Contains("数据表中的关键词字段"))
//关键词存在,不让发。
for循环结束
{
Regex reg = new Regex(@"(<a .+?</a>)|(<pre(>|\s).+?</pre>)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match mat = reg.Match(body);
List<string> str1 = new List<string>();
List<string> str2 = new List<string>();
int indx = 0;
while (mat.Success)
{
str1.Add(body.Substring(indx, mat.Index - indx));
str2.Add(mat.Value);
indx = mat.Index + mat.Length; mat = reg.Match(body, indx);
}
str1.Add(body.Substring(indx));
str2.Add(""); StringBuilder sb = new StringBuilder();
int p = 50, cnt, len;
StringBuilder tmp;
Regex reg2;
Match mat2; for (int i = 0; i < str1.Count; i++)
{
tmp = new StringBuilder(str1[i]); if (Regex.Replace(tmp.ToString(), @"<.+?>", "").Length > 5)
{
cnt = tmp.Length / p;
len = 0;
foreach (string _tag in Tag.AllTags)//AllTags包含了站内所有关键字
{
//str = Regex.Replace(str, @"([^<]+?)(" + _tag + ")", "$1<a href='/tag/$2.htm'>$2</a>", RegexOptions.IgnoreCase);
reg2 = new Regex(@"((^|>)[^<]+?)(" + _tag + ")", RegexOptions.IgnoreCase);
mat2 = reg2.Match(tmp.ToString());
if (mat2.Success)
{
tmp.Remove(mat2.Index, mat2.Length);
tmp.Insert(mat2.Index, mat2.Groups[1].Value + "<a href='/tag/" + mat2.Groups[2].Value + ".htm'>" + mat2.Groups[2].Value + "</a>");
if (++len > cnt) break;
}
}
}
sb.Append(tmp.ToString());
sb.Append(str2[i]);
}
return sb.ToString();
}
{
Regex reg = new Regex(@"(<a .+?</a>)|(<pre(>|\s).+?</pre>)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match mat = reg.Match(body);
List<string> str1 = new List<string>();
List<string> str2 = new List<string>();
int indx = 0;
while (mat.Success)
{
str1.Add(body.Substring(indx, mat.Index - indx));
str2.Add(mat.Value);
indx = mat.Index + mat.Length; mat = reg.Match(body, indx);
}
str1.Add(body.Substring(indx));
str2.Add(""); StringBuilder sb = new StringBuilder();
int p = 50, cnt, len;
StringBuilder tmp;
Regex reg2;
Match mat2; for (int i = 0; i < str1.Count; i++)
{
tmp = new StringBuilder(str1[i]); if (Regex.Replace(tmp.ToString(), @"<.+?>", "").Length > 5)
{
cnt = tmp.Length / p;
len = 0;
foreach (string _tag in Tag.AllTags)//AllTags包含了站内所有关键字
{
//str = Regex.Replace(str, @"([^<]+?)(" + _tag + ")", "$1<a href='/tag/$2.htm'>$2</a>", RegexOptions.IgnoreCase);
reg2 = new Regex(@"((^|>)[^<]+?)(" + _tag + ")", RegexOptions.IgnoreCase);
mat2 = reg2.Match(tmp.ToString());
if (mat2.Success)
{
tmp.Remove(mat2.Index, mat2.Length);
tmp.Insert(mat2.Index, mat2.Groups[1].Value + "<a href='/tag/" + mat2.Groups[2].Value + ".htm'>" + mat2.Groups[2].Value + "</a>");
if (++len > cnt) break;
}
}
}
sb.Append(tmp.ToString());
sb.Append(str2[i]);
}
return sb.ToString();
}