Ask coding questions

← Back to all posts
I need help with this
Bunnytoes (116)

I found this online and it doesn't work yet. How can I make it so it can filter out bad words?

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();
}

}

Comments
hotnewtop
xxpertHacker (930)

What about it doesn't work?

xxpertHacker (930)

@Bunnytoes You need to draw List<T> into scope first, put the following at the top of the file:

using System;
using System.Collections.Generic;

This is because you're looking for System.Collections.Generic.List.

xxpertHacker (930)

@Bunnytoes List<T>, fill in the T.

private static List<string> FilteredWords()
{
    List Filter = new List<string>();
    ...
Bunnytoes (116)

@xxpertHacker I will send you the link of the repl I made and can please fork it and fix it

xxpertHacker (930)

@Bunnytoes Just fill it in, import Regex, and add a main function. You know C#, right?

Bunnytoes (116)

@xxpertHacker Yes I know it, but please show me what you mean