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 Sausagesauce · Aug 06, 2013 at 05:10 PM · stringcontains

Check if string contains some text

I want to make a javascript check if a string contains one of two pieces of text. I figured it out, but it doesn't work. Here is my code:

 var XZ : String;
 //X or Z?
 //0=X, Y=Z
 function Update(){
     XZ.Contains("X"||"Z");
         if (true){
             Debug.LogError("XZ must be either X or Z");
             }
 }

What happens is it always returns the error no matter what. What's wrong with this?

Comment
Add comment · Show 3
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 MalachiteBR · Aug 06, 2013 at 05:30 PM 0
Share

is this JS ?

avatar image Sausagesauce · Aug 06, 2013 at 05:32 PM 0
Share

Yes, this is.

avatar image Eric5h5 · Aug 06, 2013 at 05:41 PM 0
Share

No, I'm afraid it's some made-up language.

1 Reply

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

Answer by Eric5h5 · Aug 06, 2013 at 05:43 PM

Code doesn't work like that. Contains requires you to use a string; "X"||"Z" is not a string. Also, if (true) is always true, so it's pointless to do that. I assume you're after something like

 if (XZ.Contains("X") || XZ.Contains("Z")) {
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 Sausagesauce · Aug 06, 2013 at 05:46 PM 0
Share

Thanks for that, I was really confused about what I was doing.

avatar image freedom667 · Feb 13, 2018 at 12:57 PM -1
Share

I have a question for this. what if there are two gamobjects. These names are "Object" and "Object Front". How can i check only "Front" word in if - else statement? does not work Contains. is there another way?

avatar image Eric5h5 freedom667 · Feb 13, 2018 at 07:28 PM 0
Share

If you have a question then post a question. Comments on answers isn't the place for it.

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

17 People are following this question.

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

Related Questions

List is empty when used in other method 1 Answer

if a string has certain letter(s) or number(s) 2 Answers

string.Contains() to work with string with Chinese characters? 1 Answer

I am Trying to find what position a Space is in my Array and get them to a array of floats 2 Answers

How do you check if a string has already been removed from a generic list? 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