Profanity Filter

So the biggest advice I've gotten to learn programing is to just make stuff. So I thought I'd take what I saw from my latest lesson and try and apply it into something familair. I was learning boolean expressions and how the example showed a string and how it detected if the term 'fox' was present. I thought, 'Ok I can see how that comes in handy, it's probably how websites and stuff find and filter out profanity. So I decided to make one one but every time I run it, it comes back not detecting any. Is this because I have the user input the string? Or is there something I'm missing. Also this should go without saying but the code contains a number of dirty words so it'll be blurred for those who don't want to see it.
No description
19 Replies
Angius
Angius2w ago
No description
Angius
Angius2w ago
This creates a single string: "bitchfuckshitcuntdamncockpussyassdickdyke" I don't think the message you enter contains such a string
NoobEclipse
NoobEclipse2w ago
dont take my word for it but isnt the answer as simple as putting it as ("slur1") ("slur2") etc etc?
Angius
Angius2w ago
As in, message.Contains("a")("b")("c")? No
NoobEclipse
NoobEclipse2w ago
okay so ive been looking at it and the way i originally thought is calling it like literal functions he would have to include after each slur so message.Contains("a") message.Contains("b") || essentially saying instead of all these words it has this or this or this if that makes sense?
Angius
Angius2w ago
||text|| in Markdown is a spoiler, that's why we use code blocks with backticks
NoobEclipse
NoobEclipse2w ago
its just a thought idk if it would work in practicallity
Angius
Angius2w ago
Bue yes, you're right It would work, although I pity anybody who would have to write it for 100+ words
NoobEclipse
NoobEclipse2w ago
yeah lol, surely there is an easier way around it but if its only for a basic filter it should be fine as above
Angius
Angius2w ago
An array of words + a loop, or an array of words + LINQ
NoobEclipse
NoobEclipse2w ago
i hadnt even thought of an array tbf, though im still fairly new so im proud of myself for even managing to somewhat solve this problem lmao
Jake Goodheart
Jake GoodheartOP2w ago
What's LINQ?
Angius
Angius2w ago
Kind of like list comprehension in Python
int[] nums = [ 1, 2, 3, 4, 5, 6, 7, 8, ];
var firstThreeDoubledEvens = nums
.Where(n => n % 2 == 0) // take only even numbers
.Select(n => n * 2) // multiply them all
.Take(3) // take 3 of them
.ToList(); // get a list
int[] nums = [ 1, 2, 3, 4, 5, 6, 7, 8, ];
var firstThreeDoubledEvens = nums
.Where(n => n % 2 == 0) // take only even numbers
.Select(n => n * 2) // multiply them all
.Take(3) // take 3 of them
.ToList(); // get a list
There are more methods to it, of course. Like .Any(), .Contains(), etc.
Jake Goodheart
Jake GoodheartOP2w ago
Hm, well I'll learn that eventually. Right now the solution presented works just fine. Though now I feel bad for anyone whose worked on a game chat to have to go in and think up every single type of profanity.
Angius
Angius2w ago
Sure, everything in due time Also, ready-made lists of profanities already exist for anyone to use For example https://github.com/dsojevic/profanity-list Or https://dedolist.com/lists/language/profane-words-english/api/
Jake Goodheart
Jake GoodheartOP2w ago
That's another thing I gotta learn, navigating github
NoobEclipse
NoobEclipse2w ago
you and me both, i have an account but i always forget to use it i keep forgetting just how resourceful/powerful it is lol
phaseshift
phaseshift2w ago
Next problem, have a profanity filter, but not block Scunthorpe, and other false positives
Jake Goodheart
Jake GoodheartOP3d ago
Yeah I haven't gotten that far in learning yet XD

Did you find this page helpful?