Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 FlowerCraft · Jul 24, 2012 at 08:24 AM · inputswitchchatcase

Syntax of switch + case insensitive?

So there's an input, and some commands, I want to check what people are typing in, or if it's just normal chat message. err, and I use a switch, but I also want a case insensitive on the checks. Example script, from current version of script, this works, but the input has to be case sensitive, or it won't register them..

 switch(Console Input From Player)
 {
 
 case "/example1" :
 {
 }
 break;
 
 case "/example2" :
 {
 }
 break;
 
 default :
 {
 }
 break;
Comment
Add comment · Show 4
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 Fattie · Jul 24, 2012 at 09:05 AM 0
Share

just FORCE the inco$$anonymous$$g information to be all lower case. then, compare.

makes sense?! hope it helps !

avatar image FlowerCraft · Jul 24, 2012 at 05:50 PM 0
Share

It does help, but that also means, that if it doesn't match any of the given parameters, then outputs as chat, if you say "Hi there" it'll make you look like a spelling retard and put "hi there" Although the method is valid.

avatar image Fattie · Jul 24, 2012 at 06:56 PM 1
Share

Dude - you make ANOTHER VARIABLE that has the lower case version. Use that OTHER variable to match. $$anonymous$$eep the original intact.

O$$anonymous$$? That's how you do it.

This is really basic program$$anonymous$$g questions - you should use stackoverflow. this is really more for Unity3D specific answers, I think.

avatar image pheash · Jul 24, 2012 at 08:48 PM 1
Share

certain things are not easy to figure out for beginners, esp if you are self tought like me you get weird gaps in your knowledge which might seem very basic to others but you simply didnt know about it

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FlowerCraft · Jul 24, 2012 at 10:29 PM

This was resolved by myself, before Pheash answer, posting answer for future reference to the community:

The problem was, that I couldn't assign the comparison that was case in-dependent, so what I did, was instead of adding them on a case basis, just lower casing the entire search option as follows:

 switch([STRING].ToLower () ){
Comment
Add comment · 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
0

Answer by pheash · Jul 24, 2012 at 08:45 AM

Hi, This might be more of a pointer into a possible direction, as i havent tried it or done it myself: you can use .NET functions have a look here: http://docs.unity3d.com/Documentation/ScriptReference/MonoCompatibility.html there is one in there called ToLower() which converts a string to lower case.

1) convert the user input to lower case

2) compare lowercase version to your list via switch statement

That way it doesnt matter if the user input is "\\ExAmPLe1" or "\\exaMple1"

I know that normal java has a function called: compareToIgnoreCase(String), it compares 2 strings and ignores the case. I am not 100% sure you can use that one

Comment
Add comment · Show 2 · 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 FlowerCraft · Jul 24, 2012 at 12:39 PM 0
Share

Yes, js does have that, and I'm trying to use that, but ins$$anonymous$$d of an if, then with a switch&case statement, just trying to figure the syntax of it.

avatar image pheash · Jul 24, 2012 at 05:41 PM 0
Share

I dont see anything wrong with your syntax above, aslong as "Console Input..." is replaced by a string variable holding the lowerCase version of the input. although I have read that a string stored in a variable will never be the same as another string that looks exactly the same but isnt the same object. maybe someone can confirm or clarify this point. that might be why your switch doesnt work.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

want to convert too many if statements into 1 switch case statement. error help. 2 Answers

I would like some help refactoring my code, I am working with switch cases concering the delivery of food items in my game 1 Answer

I use switch in if...it desn't work 1 Answer

Adjusting location on save to avoid infinite loop. 1 Answer

Camera switching from first person to 3rd, script not working, need help plz 1 Answer


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