- Fri Feb 18, 2011 9:43 am
#2416
In addition to the Uppercase detection mod, a group of us players were also talking about a profanity filter....
"You sir, are a complete ***** and a ***** ********."

Code: Select all
The above code returnspublic 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);
}
}
"You sir, are a complete ***** and a ***** ********."
