Created
December 4, 2014 11:59
-
-
Save woodss/408593711511cf546b8f to your computer and use it in GitHub Desktop.
PottyMouth.cs - Very simple C# Swear Word Filter Extension Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class FormattableObject | |
{ | |
/// Takes a string and applies a "cleanup" filter on it. | |
/// Returns a Family friendly string of text with any bad words replaced with | |
/// the same number of characters, only as asterisks. | |
/// Usage: myString.ToFamilyFriendlyString() | |
private static List FilteredWords() | |
{ | |
List Filter = new List(); | |
Filter.Add("sponge"); | |
Filter.Add("OSX"); | |
Filter.Add("Android"); | |
Filter.Add("person of questionable intelligence"); | |
// Add more here! | |
return Filter; | |
} | |
public static string ToFamilyFriendlyString(this object input) | |
{ | |
foreach (string fWord in FilteredWords()) | |
{ | |
// Replace the word with *'s (but keep it the same length) | |
string strReplace = ""; | |
for(int i = 0;i<=fWord.Length;i++) { | |
strReplace += "*"; | |
} | |
input = Regex.Replace(input.ToString(), fWord, strReplace, RegexOptions.IgnoreCase); | |
} | |
return input.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment