如何做到碰到关键字就给其添超链接及其如何调用此方法 求大哥哥 大姐姐了 我急用 谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static string changeStyle(string contents, DataTable dt) { //A标记中title中显示的文本改变样式 string p = ""; //获取到的关键词关联文章总数的记录条数 int kcount = ArticleKeyWordsRules.getArticleCountAll().Rows.Count; //获取最热关键词的文章数量 double max = Convert.ToDouble(ArticleKeyWordsRules.getArticleCountAll().Rows[0]["ArticleCount"]); //循环关键词列表 for (int i = 0; i < dt.Rows.Count; i++) { string dtkey = dt.Rows[i]["KeyWords"].ToString().Trim(); if (contents.Contains(dtkey)) { //根据关键词获取对应文章的总数量 int count = ArticleKeyWordsRules.getArticleCountByKeyWords(dtkey); //取出替换前的关键词 string wordsBefore = dtkey; //A标记中title显示的文本 p = wordsBefore; //给A标记的title值进行改变,以免被替换掉 for (int j = 0; j < wordsBefore.Length; j++) { //j*5 添加的字符位置,等于后面的字符长度+1 p = p.Insert(j * 5, "|@#|"); } //获取该关键词的值(绿色=蓝色=值) //double num = (1 - count / (max - min)) * 230; ////把数字转换成int型的 //int number = St.CheckIntTypePageParameterNegative1(num.ToString()); //if (number == -1) //{ // number = 230; //} //int number = Convert.ToInt32(num); double num = (1 - count / max) * 230; int number = Math.Abs(Convert.ToInt32(num)); //确定该关键词的背景色 string color = "#FF" + DtoX(number) + DtoX(number); //替换后的样式 string wordsAfter = "<a href=\"ArticleList.aspx?KeyWords=" + HttpContext.Current.Server.UrlEncode(wordsBefore) + "¤tPage=1\" title=\"关 键 词:" + p + " 文章数量:" + count + "\" target=\"_blank\"><span style=\"background-color:" + color + ";\">" + wordsBefore + "</span></a>"; contents = contents.Replace(wordsBefore, wordsAfter); } } //把|@#|替换掉 contents = contents.Replace("|@#|", ""); //返回内容 return contents; } public static string changeStyle(string contents, DataTable dt) { //A标记中title中显示的文本改变样式 string p = ""; //获取到的关键词关联文章总数的记录条数 int kcount = ArticleKeyWordsRules.getArticleCountAll().Rows.Count; //获取最热关键词的文章数量 double max = Convert.ToDouble(ArticleKeyWordsRules.getArticleCountAll().Rows[0]["ArticleCount"]); //循环关键词列表 for (int i = 0; i < dt.Rows.Count; i++) { string dtkey = dt.Rows[i]["KeyWords"].ToString().Trim(); if (contents.Contains(dtkey)) { //根据关键词获取对应文章的总数量 int count = ArticleKeyWordsRules.getArticleCountByKeyWords(dtkey); //取出替换前的关键词 string wordsBefore = dtkey; //A标记中title显示的文本 p = wordsBefore; //给A标记的title值进行改变,以免被替换掉 for (int j = 0; j < wordsBefore.Length; j++) { //j*5 添加的字符位置,等于后面的字符长度+1 p = p.Insert(j * 5, "|@#|"); } //获取该关键词的值(绿色=蓝色=值) //double num = (1 - count / (max - min)) * 230; ////把数字转换成int型的 //int number = St.CheckIntTypePageParameterNegative1(num.ToString()); //if (number == -1) //{ // number = 230; //} //int number = Convert.ToInt32(num); double num = (1 - count / max) * 230; int number = Math.Abs(Convert.ToInt32(num)); //确定该关键词的背景色 string color = "#FF" + DtoX(number) + DtoX(number); //替换后的样式 string wordsAfter = "<a href=\"ArticleList.aspx?KeyWords=" + HttpContext.Current.Server.UrlEncode(wordsBefore) + "¤tPage=1\" title=\"关 键 词:" + p + " 文章数量:" + count + "\" target=\"_blank\"><span style=\"background-color:" + color + ";\">" + wordsBefore + "</span></a>"; contents = contents.Replace(wordsBefore, wordsAfter); } } //把|@#|替换掉 contents = contents.Replace("|@#|", ""); //返回内容 return contents; } http://topic.csdn.net/u/20101228/13/d6da0e26-0c98-480a-bb39-569c2f939b36.html 关键字存持久化介质中,系统启动后读入内存。加过滤器,对每一提交,用正则进行匹配算法或者这种在网站后台设置过滤字符void Application_BeginRequest(object sender, EventArgs e){ for (int i=0; i < Request.Form.Count;i++) { if (Request.Form[i].ToString() == "__VIEWSTATE") continue; if (IsM(Request.Form[i].ToString())) { Response.Write("您提交的内容中含有非法字符."); Response.End(); } } }protected bool IsM(string InText){ string word = @""; if (InText == null) return false; if (Regex.IsMatch(InText,word)) return true; return false;} Regex.Replace数据库,XML,List都可保存 100分请教ETAG的配置 下载文件问题 求repeater的编辑更新删除操作! Jquery 问题。k.data.action(k,i,j) 百度音乐第二次点播放不会弹出新页面,这是怎么做到的 如何控制ListView某一行的Style属性 web页面打印不完全 多个base64编码组成的字符串如何拆分? 求救!问题解决马上结贴! 今天和女朋友分手了,心情不好,散分! 如何做到碰到关键字就给其添超链接及其如何调用此方法 div的内容读取问题
{
//A标记中title中显示的文本改变样式
string p = "";
//获取到的关键词关联文章总数的记录条数
int kcount = ArticleKeyWordsRules.getArticleCountAll().Rows.Count;
//获取最热关键词的文章数量
double max = Convert.ToDouble(ArticleKeyWordsRules.getArticleCountAll().Rows[0]["ArticleCount"]);
//循环关键词列表
for (int i = 0; i < dt.Rows.Count; i++)
{
string dtkey = dt.Rows[i]["KeyWords"].ToString().Trim();
if (contents.Contains(dtkey))
{
//根据关键词获取对应文章的总数量
int count = ArticleKeyWordsRules.getArticleCountByKeyWords(dtkey);
//取出替换前的关键词
string wordsBefore = dtkey;
//A标记中title显示的文本
p = wordsBefore;
//给A标记的title值进行改变,以免被替换掉
for (int j = 0; j < wordsBefore.Length; j++)
{
//j*5 添加的字符位置,等于后面的字符长度+1
p = p.Insert(j * 5, "|@#|");
}
//获取该关键词的值(绿色=蓝色=值) //double num = (1 - count / (max - min)) * 230;
////把数字转换成int型的
//int number = St.CheckIntTypePageParameterNegative1(num.ToString());
//if (number == -1)
//{
// number = 230;
//}
//int number = Convert.ToInt32(num); double num = (1 - count / max) * 230;
int number = Math.Abs(Convert.ToInt32(num)); //确定该关键词的背景色
string color = "#FF" + DtoX(number) + DtoX(number);
//替换后的样式
string wordsAfter = "<a href=\"ArticleList.aspx?KeyWords=" + HttpContext.Current.Server.UrlEncode(wordsBefore) + "¤tPage=1\" title=\"关 键 词:" + p + " 文章数量:" + count + "\" target=\"_blank\"><span style=\"background-color:" + color + ";\">" + wordsBefore + "</span></a>";
contents = contents.Replace(wordsBefore, wordsAfter);
}
}
//把|@#|替换掉
contents = contents.Replace("|@#|", "");
//返回内容
return contents;
}
{
//A标记中title中显示的文本改变样式
string p = "";
//获取到的关键词关联文章总数的记录条数
int kcount = ArticleKeyWordsRules.getArticleCountAll().Rows.Count;
//获取最热关键词的文章数量
double max = Convert.ToDouble(ArticleKeyWordsRules.getArticleCountAll().Rows[0]["ArticleCount"]);
//循环关键词列表
for (int i = 0; i < dt.Rows.Count; i++)
{
string dtkey = dt.Rows[i]["KeyWords"].ToString().Trim();
if (contents.Contains(dtkey))
{
//根据关键词获取对应文章的总数量
int count = ArticleKeyWordsRules.getArticleCountByKeyWords(dtkey);
//取出替换前的关键词
string wordsBefore = dtkey;
//A标记中title显示的文本
p = wordsBefore;
//给A标记的title值进行改变,以免被替换掉
for (int j = 0; j < wordsBefore.Length; j++)
{
//j*5 添加的字符位置,等于后面的字符长度+1
p = p.Insert(j * 5, "|@#|");
}
//获取该关键词的值(绿色=蓝色=值) //double num = (1 - count / (max - min)) * 230;
////把数字转换成int型的
//int number = St.CheckIntTypePageParameterNegative1(num.ToString());
//if (number == -1)
//{
// number = 230;
//}
//int number = Convert.ToInt32(num); double num = (1 - count / max) * 230;
int number = Math.Abs(Convert.ToInt32(num)); //确定该关键词的背景色
string color = "#FF" + DtoX(number) + DtoX(number);
//替换后的样式
string wordsAfter = "<a href=\"ArticleList.aspx?KeyWords=" + HttpContext.Current.Server.UrlEncode(wordsBefore) + "¤tPage=1\" title=\"关 键 词:" + p + " 文章数量:" + count + "\" target=\"_blank\"><span style=\"background-color:" + color + ";\">" + wordsBefore + "</span></a>";
contents = contents.Replace(wordsBefore, wordsAfter);
}
}
//把|@#|替换掉
contents = contents.Replace("|@#|", "");
//返回内容
return contents;
}
在网站后台设置过滤字符
void Application_BeginRequest(object sender, EventArgs e)
{
for (int i=0; i < Request.Form.Count;i++)
{
if (Request.Form[i].ToString() == "__VIEWSTATE") continue;
if (IsM(Request.Form[i].ToString()))
{
Response.Write("您提交的内容中含有非法字符.");
Response.End();
} }
}
protected bool IsM(string InText)
{
string word = @"";
if (InText == null)
return false;
if (Regex.IsMatch(InText,word))
return true;
return false;
}
Regex.Replace
数据库,XML,List都可保存