1

I have created an Android app wherein the users can give reviews and comments the products. Is there a way to control users from writing bad words in the reviews and comments or is there any sdk available for doing that.

Matthias
  • 4,481
  • 12
  • 45
  • 84
user3517929
  • 235
  • 1
  • 7

2 Answers2

1

Do it server side if you're using php and If you're just trying to do a simple word filter, create a single long regexp with all of the banned phrases that you want to censor, and merely do a regex find/replace with it. A regex like:

$filterRegex = "(boogers|snot|poop|shucks|argh|fudgecicles)"

and run it on your input string using preg_match() to wholesale test for a hit,

or preg_replace() to blank them out.

Rohit Suthar
  • 3,528
  • 1
  • 42
  • 48
M4HdYaR
  • 1,124
  • 11
  • 27
1

You have to create a class for the censor module, this is somewhat greedy in implementation.

public class WordFilter {

    static String[] words = {"bad", "words"};

    public static String censor(String input) {
        StringBuilder s = new StringBuilder(input);
        for (int i = 0; i < input.length(); i++) {
            for (String word : words) {
                try {
                    if (input.substring(i, word.length()+i).equalsIgnoreCase(word)) {
                        for (int j = i; j < i + word.length(); j++) {
                            s.setCharAt(j, '*');
                        }
                    }
                } catch (Exception e) {
                }
            }
        }
        return s.toString();
    }

    public static void main(String[] args) {
        System.out.println(censor("String with bad words"));
    }
}
Jon Church
  • 2,320
  • 13
  • 23