asp.net敏感词过滤(二)

 

 

前台调用:

Stopwatch sw = new Stopwatch();
            sw.Start();           
            clsFilter filter = new clsFilter("", this.ReadWords());
             filter.words = mod.bsTitle + mod.bsKey + mod.bsContent;//标题,关键字,内容
             filter.Filter();
            Dictionary> ret = filter.result;//得到结果列表
            sw.Stop();
            this.ltResult.Text = string.Format("字数为:{4}
1级的有:{0}
2级的有:{1}
3级的有:{2}
过滤时间为:{3}ms", ret.ContainsKey(1) ? ret[1].Count : 0, ret.ContainsKey(2) ? ret[2].Count : 0, ret.ContainsKey(3) ? ret[3].Count : 0, sw.ElapsedMilliseconds, this.txtKeys.Text.Length);

 

 //加载词库字符串
        private string ReadWords()
        {
            StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath("/Manage/Log/minganci.config"), Encoding.GetEncoding("UTF-8"));
            string s = sr.ReadToEnd();
            sr.Close();
            sr.Dispose();
            return s;
        }


敏感词库的格式为(敏感词|等级):


足球玩法|1
操*妈|3
冰火九重|2

 

 

若有人知道更好的过滤方式,可以在此分享下(QQ:1577592799).......

你可能感兴趣的:(ASP.NET,asp.net,string,filter,qq)