All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP会话(Session)使用入门
Asp.Net、Ado.net,数据库编程超级攻略_[Asp.Net教程]
初学PHP指导:php.ini 配置详细选项_[PHP教程]
.net操纵xml文件类
如何在Windows配置整合PHP和MySQL_php资料_编程技术
ASP.Net生成后台脚本的问题的解决办法_[Asp.Net教程]
PHP对GB编码动态转UTF-8编码的几种方法评测_[PHP教程]
ASP.NET Remoting体系结构(二)
数据库连接URL中分号引发的错误_.net资料_编程技术
面向Visual,Basic开发人员的ASP.NET,2.0简介_.net资料_编程技术
Reading number is top 10 pictures
Chinese paper-cut grilles art appreciation8
到底是谁撞谁呀?
Beautiful Japanese beauty(漂亮的日本美女)2
Ashlynn Brooke photograph of a group2
初五接财神啦!五路财神齐来到
网上疯传的一篇小学作文《爸爸也治不了妈妈》
Cesarean section, bloody, silently into it!1
Look for from human art net, is good--2
Fan bingbing black wings for platform and DanLuoWang believes beauty2
Summer is most suitable for young people to travel in China4
Download software ranking
金山office2007
Professional killers2 data package
I'm come from Beijing1
apache-tomcat-6.0.33
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
Sora aoi‘s film--Lust fan wall
Tram sex maniac 2 (H) rar bag19
Visual C++界面编程技术
电车之狼R
VeryCD电驴(EasyMule) V1.1.9 Build09081
aaa published in(发表于) 2013/12/18 8:07:56 Edit(编辑)
关于.NET脏字过滤的算法代码_.net资料_编程技术

关于.NET脏字过滤的算法代码_.net资料_编程技术

关于.NET脏字过滤的算法代码_.net资料_编程技术-你的首页-uuhomepage.com

  关于.NET脏字过滤的算法代码。我这里测试的时候,RegEx要快一倍左右。但是还是不太满意,应为我们网站上脏字过滤用的相当多,对效率已经有了一些影响,经过一番思考后,自己做了一个算法。在自己的机器上测试了一下,使用原文中的脏字库,0x19c的字符串长度,1000次循环,文本查找耗时1933.47ms,RegEx用了1216.719ms,而我的算法只用了244.125ms.


  主要算法如代码所示


  private static Dictionary dic = new Dictionary();
  private static BitArray fastcheck = new BitArray(char.MaxValue);
  static void Prepare()
  {
  string[] badwords = // read from file
  foreach (string word in badwords)
  {
  if (!dic.ContainsKey(word))
  {
  dic.Add(word, null);
  maxlength = Math.Max(maxlength, word.Length);
  int value = word[0];
  fastcheck[word[0]] = true;
  }
  }
  }


  使用的时候


  int index = 0;
  while (index < target.Length)
  {
  if (!fastcheck[target[index]])
  {
  while (index < target.Length - 1 && !fastcheck[target[++index]]) ;
  }
  for (int j = 0; j < Math.Min(maxlength, target.Length - index); j++)
  {
  string sub = target.Substring(index, j);
  if (dic.ContainsKey(sub))
  {
  sb.Replace(sub, "***", index, j);
  index += j;
  break;
  }
  }
  index++;
  }


  我们在遇到问题的时候不要一味地去借用别人的代码,有时候动动脑筋说不定有意外的惊喜!





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.