Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Swear word filter

  Asked By: Anita    Date: Aug 04    Category: Java    Views: 2166
  

I was wondering, if the easiest way to filter for bad words in java?


Is just having a for loop and testing each value by using Replaceall
string statement?


What do you guys think?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Pravat Jainukul     Answered On: Aug 04

> string []swear= { "swearword1", "swearword2", "swearword3"
> };

> string=" Here is some type of string a user owuld enter "

Huh?

> for(int i=0; i< swear.size(); i++)
> if(str.indexOf(swear[i])>=0)
> replace.All(swear[i], "***")

public class MyFiler {

public static void main(String args[]) {
string input = "Parse this sentance";
StringTokenizer st = new StringTokenizer(input);

while (st.hasMore()) {
String word  = st.next();
for (int i=0; i<swear.length(); i++) {
if(swear[i].equals(word)) {
word="*";
}
}
}
}
}

 
Didn't find what you were looking for? Find more on Swear word filter Or get search suggestion and latest updates.




Tagged: