Page 1 of 1

[Chat] Profanity filter

Posted: Fri Feb 18, 2011 9:43 am
by Sharingan616
In addition to the Uppercase detection mod, a group of us players were also talking about a profanity filter....
Code: Select all
public class SwearFilter{
  public static void main(String[] args){
    
    String playertext = "You sir, are a complete idiot and a loser duckster.";
    String part1;
    String swear;
    String part2;
    String replacement = "";
    int word;
    int length;
    String bannedwords[] = {"idiot", "loser", "duckster", "meanie", "noob"};
    
    for(int i = 0; i < bannedwords.length; i++){
      word = playertext.indexOf(bannedwords[i]);
      length = bannedwords[i].length();
      if(word != -1){
        part1 = playertext.substring(0,word);
        swear = playertext.substring(word, word+length);
        part2 = playertext.substring(word+length, playertext.length());
        
        for (int x=0; x<  swear.length(); x++)
          replacement = replacement + "*";
        
        playertext = part1+replacement+part2;
        replacement = "";
      }
    }
    System.out.println(playertext);
  }
}
The above code returns
"You sir, are a complete ***** and a ***** ********."

:D

Re: [Chat] Profanity filter

Posted: Tue Feb 22, 2011 8:07 pm
by jailbird556
Sharingan616 wrote:In addition to the Uppercase detection mod, a group of us players were also talking about a profanity filter....
Code: Select all
public class SwearFilter{
  public static void main(String[] args){
    
    String playertext = "You sir, are a complete idiot and a loser duckster.";
    String part1;
    String swear;
    String part2;
    String replacement = "";
    int word;
    int length;
    String bannedwords[] = {"idiot", "loser", "duckster", "meanie", "noob"};
    
    for(int i = 0; i < bannedwords.length; i++){
      word = playertext.indexOf(bannedwords[i]);
      length = bannedwords[i].length();
      if(word != -1){
        part1 = playertext.substring(0,word);
        swear = playertext.substring(word, word+length);
        part2 = playertext.substring(word+length, playertext.length());
        
        for (int x=0; x<  swear.length(); x++)
          replacement = replacement + "*";
        
        playertext = part1+replacement+part2;
        replacement = "";
      }
    }
    System.out.println(playertext);
  }
}
The above code returns
"You sir, are a complete ***** and a ***** ********."

:D
this would only be for swearing and replacment of swears like shiznit and frig or somethin not idiot or Duckster????

Re: [Chat] Profanity filter

Posted: Tue Feb 22, 2011 9:13 pm
by Sharingan616
jailbird556 wrote:
Sharingan616 wrote: this would only be for swearing and replacment of swears like shiznit and frig or somethin not idiot or Duckster????
The banned words specified in this example can be replaced with any amount of different words. The words that would be blocked would be the F word, the S word, the N word, stuff like that. All you have to do is replace the words "idiot", "loser", "duckster", "meanie", and "noob" with the swear words.

Re: [Chat] Profanity filter

Posted: Tue Feb 22, 2011 9:30 pm
by jailbird556
Sharingan616 wrote:
jailbird556 wrote:
Sharingan616 wrote: this would only be for swearing and replacment of swears like shiznit and frig or somethin not idiot or Duckster????
The banned words specified in this example can be replaced with any amount of different words. The words that would be blocked would be the F word, the S word, the N word, stuff like that. All you have to do is replace the words "idiot", "loser", "duckster", "meanie", and "noob" with the swear words.
lol thats what i ment

Re: [Chat] Profanity filter

Posted: Tue Feb 22, 2011 9:35 pm
by Sharingan616
jailbird556 wrote: lol thats what i ment
ya haha :P

Re: [Chat] Profanity filter

Posted: Thu Feb 24, 2011 2:21 pm
by Sharingan616
There's some problems with the code. Working on it now.