Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by oliver-jones · Jun 16, 2011 at 04:44 PM · stringsearchkeyword

Search A String For Keyword - Profanity

Hello,

I have a GUI TextField in my game where you can submit a string of text to my server.

What I want to do though, is to search the string for any profanity and offensive words before submitting.

 if(GUI.Button(Rect(100,120,150,30),"Create")){
    if(newPlayer == "f**k" || newPlayer == "s**t"){
       print("Profanity Found");
    }
    else{
       AddVariables();
    }
 }

The problem with the methord I'm using is that it will only pull the string if it says "f--k" - where as some genius might submit "KingOfF--King". So is there a way to search the whole string for specific keywords and pull it up?

Thanks :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by terdos · Jun 16, 2011 at 05:01 PM

newPlayer.IndexOf("f**k") will return the position in the string that f**k occurs, or -1 if it does not exist.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Jun 16, 2011 at 05:33 PM 0
Share

Cool - is there a way to search multiple keywords? Or will I just have to do an OR: newPlayer.IndexOf("f--k") || newPlayer.IndexOf("s--t")

avatar image terdos · Jun 16, 2011 at 05:39 PM 0
Share

You will very likely have to check for each word you are looking for separately. A simple loop through an array of keywords will work fine, or if you only have a few you can use || in one big if statement.

Another option would be to use regular expressions, I however do not know what support for that exists in mono.

avatar image oliver-jones · Jun 16, 2011 at 05:44 PM 0
Share

Okay, one more thing - will this work for strings like "iamoneuglyf--ker" - so its all one word.

avatar image Bunny83 · Jun 16, 2011 at 05:54 PM 0
Share

It doesn't matter. IndexOf just looks for character sequences. There is nothing like a "word" :D. It's one string. Be careful with your keywords. In some names you will get false alerts...

$$anonymous$$IsExpert --> tomiSEXpert

avatar image oliver-jones · Jun 16, 2011 at 05:57 PM 0
Share

Okay - I have tried this methord (with || or || statements) and if I, for example type in 'hello', I get a 'profanity found' - why do you think that is?

Show more comments
avatar image
2

Answer by Bunny83 · Jun 16, 2011 at 06:24 PM

A short example:

 var keywords : String[] = (new Array("fuck", "shit")).ToBuiltin(String);
 
 function CheckForProfanity(text : String) : boolean
 {
     text = text.ToLower(); // make the string lower case so we can search for the keywords case-insensitive.
     for(var keyword:String in keywords)
     {
         if (text.IndexOf(keyword)>=0)
             return true;
     }
     return false;
 }

To check a string do:

 var newPlayerName = "TestName";
 
 if (CheckForProfanity(newPlayerName))
 {
     Debug.Log("illegal word detected");
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · Sep 17, 2011 at 05:48 AM 0
Share

interesting that unity answers does not have auto-censor enabled

avatar image syclamoth · Sep 18, 2011 at 05:11 AM 0
Share

now why would it do that?

avatar image Bunny83 · Sep 18, 2011 at 05:40 AM 0
Share

Well, It's code. It would be a pain if it would censor parts of it based on some restricted words.

$$anonymous$$ethod names like WashItClean() would become Was**tClean, that's not really helpful ;)

 DebrisHitPoint --> Debris**tPoint
 BackupIssue    --> Backup**sue

Or you talk about the program$$anonymous$$g language Brainfuck :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you check if a string has already been removed from a generic list? 1 Answer

string deleting 1 Answer

Check for a Single word in a String (JS) 1 Answer

string searching question 1 Answer

Searching XML document 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges