Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Kenn_San · Dec 13, 2015 at 02:45 PM · arraystring

Comparing a string to an array extraction?

Hoping someone can assist as I'm pulling my hair out. I've got an array that is pulling its lines from a text document where each line of text is an array entry, works no issue.

However I'm trying to compare a line from the array as text but it doesn't seem to be working.

 string lineToCheck = textLines[currentLine];
 print (lineToCheck);
 
 if(lineToCheck=="thing"){
     print ("well it worked I guess?");
 }

lineToCheck is definitely appearing as thing but when compared just isn't picking up that it should be matching. Can someone point out where I'm going wrong?

I've also tried utilizing ToString but no dice.

I have looked around the net before resorting to bothering the community but I really just cannot figure out where my hiccup is.

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

1 Reply

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

Answer by OncaLupe · Dec 13, 2015 at 10:39 PM

My guess is there's a hidden character, like a newline, from when it was read in. You can use print(lineToCheck + "~" + lineToCheck.Length); to see how long the saved string is, and if there is a newline in there it'd show up in the console with "~6" below "thing".

You can remove special characters like that with:

 lineToCheck = lineToCheck.Replace("\n","");
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 Kenn_San · Dec 14, 2015 at 04:23 AM 0
Share

You legend, that's the one - not sure how this didn't even occur to me.

The length check caught out the hidden character but not as a new line but carriage return ins$$anonymous$$d (ie. \r) ins$$anonymous$$d.

Thank you so much for your quick and helpful assistance!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how can i split a word to individual letters..?? 2 Answers

Array Slit String and Send NGUI text 0 Answers

Newbie Problem with Multidimensional Arrays in JavaScript 0 Answers

Split String into Arrays 1 Answer

Get JSON array object string value 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