-
Bad word filter too keen.........
I am working on a bad word filter for an online chatroom which is working...... however it is also stopping words that contain a bad word.
ie
bad word that is banned - turd
good word that is also banned - saturday
the code i'm using is......
if (this.message_txt.text.indexOf("turd") != -1)
any ideas how to make the word ban so that it is precise and only bans the specific word.
cheers
J
-
Mental Ward Patient
check for the length of the string its checking, and see if its the length is the same as the word ur trying to block against.
-
Lifetime Friend of Site Staff
It's not a perfect solution but you can add spaces before and after the offensive word and avoid partial matches inside other words. Things like punctuation will mess this up, but it's better than censoring saturday
if (this.message_txt.text.indexOf(" "+turd+" ") != -1)
As your bad word list grows this kind of solution is going to slow things down. You might want to look into a solution designed from the start to find multiple words in strings without rescanning the source string every time.
Last edited by Northcode; 09-28-2005 at 11:35 AM.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|