Exemplo n.º 1
0
 public void FilterCheck()
 {
     cursor = 0;
     if (sourctText != string.Empty)
     {
         char[] tempString = sourctText.ToCharArray();;
         for (int i = 0; i < SourctText.Length; i++)
         {
             //查询以该字为首字符的词组
             WordGroup group = MEMORYLEXICON[(int)ToDBC(SourctText)[i]];
             if (group != null)
             {
                 for (int z = 0; z < group.Count(); z++)
                 {
                     string word = group.GetWord(z);
                     if (word.Length == 0 || Check(word))
                     {
                         IsSensitive = true;
                         string blackword = string.Empty;
                         for (int pos = 0; pos < wordlenght + 1; pos++)
                         {
                             blackword += tempString[pos + cursor].ToString();
                         }
                         illegalWords.Add(blackword);
                         cursor = cursor + wordlenght;
                         i      = i + wordlenght;
                     }
                 }
             }
             cursor++;
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 查找并替换
 /// </summary>
 /// <param name="replaceChar"></param>
 public static string Filter(string text, char replaceChar = '*')
 {
     cursor     = 0;
     wordlenght = 0;
     IllegalWords.Clear();
     SourctText = text;
     if (SourctText != string.Empty)
     {
         char[] tempString = SourctText.ToCharArray();
         for (int i = 0; i < SourctText.Length; i++)
         {
             //查询以该字为首字符的词组
             WordGroup group = MEMORYLEXICON[(int)ToDBC(SourctText)[i]];
             if (group != null)
             {
                 for (int z = 0; z < group.Count(); z++)
                 {
                     string word = group.GetWord(z);
                     if (word.Length == 0 || Check(word))
                     {
                         string blackword = string.Empty;
                         for (int pos = 0; pos < wordlenght + 1; pos++)
                         {
                             if ((pos + cursor) >= tempString.Length)
                             {
                                 continue;
                             }
                             blackword += tempString[pos + cursor].ToString();
                             tempString[pos + cursor] = replaceChar;
                         }
                         IllegalWords.Add(blackword);
                         cursor = cursor + wordlenght;
                         i      = i + wordlenght;
                     }
                 }
             }
             cursor++;
         }
         return(new string(tempString));
     }
     else
     {
         return(string.Empty);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 查找并替换
        /// </summary>
        /// <param name="replaceChar"></param>
        public string Filter(char replaceChar)
        {
            if (sourctText != string.Empty)
            {
                char[] tempString = sourctText.ToCharArray();

                var dbcarray = ToDBC(SourctText);
                int index;
                for (int i = 0; i < SourctText.Length; i++)
                {
                    if (dbcarray.Length <= i)
                    {
                        continue;
                    }
                    index = (int)dbcarray[i];
                    WordGroup group = MEMORYLEXICON[index];
                    if (group != null)
                    {
                        for (int z = 0; z < group.Count; z++)
                        {
                            string word = group.GetWord(z);
                            if (word.Length == 0 || Check(word))
                            {
                                string blackword = string.Empty;
                                for (int pos = 0; pos < wordlenght + 1; pos++)
                                {
                                    blackword += tempString[pos + cursor].ToString();
                                    tempString[pos + cursor] = replaceChar;
                                }
                                illegalWords.Add(blackword);
                                cursor = cursor + wordlenght;
                                i      = i + wordlenght;
                            }
                        }
                    }
                    cursor++;
                }
                return(new string(tempString));
            }
            else
            {
                return(string.Empty);
            }
        }