Noodle/Helpers/Censor.cs
/// <summary>
/// Removes the profanity from text.  Example: This is a test     .
/// </summary>
/// <param name="str">The STR.</param>
/// <returns></returns>
Removes the profanity from text.  Example: This is a test     .
Removes the profanity from text . Example : This is a test .
public static string RemoveFromText(string str)
        {
            if (string.IsNullOrEmpty(str))
                return null;
            List<string> foundWords = new List<string>();
            var censoredText = str;
            var isInappropriate = IsInappropriate(censoredText);
            if (isInappropriate)
            {
                foreach (string censoredWord in _allWords)
                {
                    string regularExpression = ToRegexPattern(censoredWord);
                    censoredText = Regex.Replace(censoredText, regularExpression, RemoveCensoredMatch,
                                                 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                }
            }
            var foundWordsWithoutDupes = foundWords.Distinct().ToList();
            if (foundWordsWithoutDupes.Count > 0)
                Log.Instance.Trace("\r\n*** String under test: {0} \r\n*** Inappropriate words found: {1}", str, string.Join(",", foundWords));
            return censoredText;
        }
public static string RemoveFromText ( string str ) { if ( string . IsNullOrEmpty ( str ) ) return null ; List < string > foundWords = new List < string > ( ) ; var censoredText = str ; var isInappropriate = IsInappropriate ( censoredText ) ; if ( isInappropriate ) { foreach ( string censoredWord in _allWords ) { string regularExpression = ToRegexPattern ( censoredWord ) ; censoredText = Regex . Replace ( censoredText , regularExpression , RemoveCensoredMatch , RegexOptions . IgnoreCase | RegexOptions . CultureInvariant ) ; } } var foundWordsWithoutDupes = foundWords . Distinct ( ) . ToList ( ) ; if ( foundWordsWithoutDupes . Count > 0 ) Log . Instance . Trace ( " \r \n \r \n " , str , string . Join ( " " , foundWords ) ) ; return censoredText ; }
Removes the profanity from text.
Removes the profanity from text .
//filter all words/phrases/patterns first // check for preceding special character //remove dupes
None
str
string
None