I am currently working on a scoreboard and I would like to find a elegant way to implement a profanity filter. Right now I am using a lot of variables (so that I can change it afterwards).
It is horrible
Develop games in your browser. Powerful, performant & highly capable.
Nevermind, I found it myself.
Here's a screenshot for anyone looking for something similar.
You should also check if part of the name matches each key. You can do that by checking if find(scorePlayerName.Text, ProfanityFilterDictionary.CurrentValue) is different from -1. If it is, it means the key is included in that player's name and should be filtered, if it is equal to -1 the key was not found and the name is fine.
Your method would detect if a player used "Fuck" as name, but would not detect if he used "Fuck1"
The find method above would return 0 for both "Fuck" and "Fuck1", meaning the key was found and should be filtered.
Also, you should save all keys in lowercase and test the lowercase(scorePlayerName.Text) against them. This would avoid players from getting away with it by writing "fUcK" for instance.
I wasn't aware that is possible :3
Oh. I didn't notice the check you make is "case insensitive". Duh!
brunopalermo The usage of the find function is still really useful ^^
Glad to help!
A quick addition: trim.