コード例 #1
0
        public String CheckSensitiveWord(String text)
        {
            ContentCheck check = new ContentCheck(library, text); //实例化 内容检测类
            var          str   = check.SensitiveWordsReplace();   //调用 敏感词替换方法 返回处理过的字符串

            return(str);
        }
コード例 #2
0
        /// <summary>
        /// 替换敏感词
        /// </summary>
        /// <param name="library">敏感词库</param>
        /// <param name="text">检测文本</param>
        /// <param name="newChar">替换字符</param>
        /// <returns></returns>
        public static string SensitiveWordsReplace(WordsLibrary library, string text, char newChar = '*')
        {
            Dictionary <int, char> dic = new ContentCheck(library).WordsCheck(text);

            if (dic != null && dic.Keys.Count > 0)
            {
                char[] chars = text.ToCharArray();
                foreach (var item in dic)
                {
                    chars[item.Key] = newChar;
                }

                text = new string(chars);
            }

            return(text);
        }
コード例 #3
0
        /// <summary>
        /// 查找敏感词
        /// </summary>
        /// <param name="library">敏感词库</param>
        /// <param name="text">检测文本</param>
        /// <returns></returns>
        public static List <string> FindSensitiveWords(WordsLibrary library, string text)
        {
            ContentCheck check = new ContentCheck(library, text);

            return(check.FindSensitiveWords());
        }