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
4
Question by zmar0519 · Apr 10, 2011 at 07:19 PM · guistringtextarea

How to tell if a string contains some specified text

Hi, everyone. I was wondering if there was a way to check if there was a way to tell if the user enters some text into a text area and do something about it. That is, the user inputs "Login" at the end of a string and I want it to delete "Login" and add "Type the password \n password: ". How do I do this? Any help would be appreciated. If this is still not clear, then please post a comment.

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

6 Replies

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

Answer by by0log1c · Apr 10, 2011 at 08:18 PM

I think

userString.Contains("stringToSearchFor")

would return either true or false.

Comment
Add comment · Show 1 · 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 zmar0519 · Apr 10, 2011 at 09:36 PM 0
Share

Thank you so much. I'm an idiot for not thinking of that.

avatar image
2

Answer by Meltdown · Apr 10, 2011 at 07:48 PM

If you're using C#, take a look at the IndexOf() and ToUpper() string methods.

If you're using JavaScript, take a look at the IndexOf() and toUpperCase() methods.

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 zmar0519 · Apr 10, 2011 at 07:57 PM 0
Share

Sorry, but my example must have mislead you. What I actually want to do is have the user input "Login" at the end of a string and for it to delete "Login" and add "Type the password \n password: ". I will edit my question accordingly.

avatar image Eric5h5 · Apr 10, 2011 at 08:32 PM 0
Share

String methods are part of $$anonymous$$ono/.net; they're not related to C#. They work in all languages. JS in Unity doesn't have "toUpperCase()", it uses .net, so all the string methods are the same as in other languages that use .net.

avatar image
1

Answer by Kenneth Sills · Apr 11, 2011 at 12:43 AM

If you are using C# then heres an example, with comments:
//Load your stuff
using System.Collections;
using System.IO;

namespace example
{
public void justAnExample() {
//Just a streamreader to read a string from a doc
StreamReader sr = new StreamReader("C:/Whatever/example.txt")
//Heres what you want, sr.IndexOf("LALALA") finds where the string of "LALALA" is located //in the stringreader. If it is not there it's -1, so if it's greater than -1 it's there.
if (sr.IndexOf("LALALA") > -1)
{
doStuff();
}
}

}

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 santi5655 · Jun 07, 2013 at 11:01 PM

you can do this

 if(yourString in stringToSearchFor)
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 santi5655 · Jun 07, 2013 at 11:00 PM

here is an easy example for doing this

 var passwordEnterString : String;
 var correctPassword : String;
 
 function Update()
 {
          if(correctPassword in passwordEnterString)
                 passwordEnterString = "correct";
 
 }
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
  • 1
  • 2
  • ›

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The code see the target First Person Controller only 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Resize GUI TextArea with text height 2 Answers

What is the best way to concatenate string to create an interaction logging console? 4 Answers

Setting Scroll View Width GUILayout 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