一佳一

记录像1+1一样简洁的代码

导航

C#过滤关键字

Posted on 2012-11-30 10:13  一佳一  阅读(751)  评论(0编辑  收藏  举报

        /// <summary>
        /// 过滤关键字
        /// </summary>
        /// <param name="value">过滤字眼,用| 隔开</param>
        /// <param name="text">传入要过滤的数据</param>
        /// <returns></returns>
        public List<string> FriterText(string value, string text)
        {
            List<string> FriterList = new List<string>();
            String regex = string.Format("({0})", value);
            //String regex = "(插你|企业|企业家)";
            Regex rg = new Regex(regex);
            if (rg.IsMatch(text))
            {
                MatchCollection mc = rg.Matches(text);
                foreach (var item in mc)
                {
                    if (!FriterList.Contains(item.ToString()))
                        FriterList.Add(item.ToString());
                }
            }
            return FriterList;
        }

 

 

附带关键字过滤文件https://files.cnblogs.com/linyijia/%E5%85%B3%E9%94%AE%E5%AD%97.rar