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
0
Question by gadashi12 · May 03, 2019 at 10:57 PM · networkingstringif-statementssyntax

Comparing text from www.downloadhandler.text to string does not work

I have created a script that gets data from a php script. I want to check if I got back "0 results" so I have this code:

             Debug.Log(www.downloadHandler.text);
             if(www.downloadHandler.text == "0 results") { 
                 Debug.Log("it works");
             }

In the Unity adder it first logs "0 results" but it never logs "it works". From the first log I can tell www.downloadHandler.text and "0 results" are the same string but the if statement is false...

Is downloadhandler.text a different format than string or what am I missing?

Please help, thank you

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
1
Best Answer

Answer by JDelekto · May 03, 2019 at 11:20 PM

What you might want to do is assign the results of your www.downloadHandler.text to a string variable before the comparison. I also usually prefer to use the .Equals() method to compare strings as well.

For example:

 string result = www.downloadHandler.text;
 if (result.Equals("0 results")) { ... }

I'm not quite sure what may be happening in your case, but I'm wondering if you're receiving a UTF-8 string while strings in .NET are in Unicode. There is probably a conversion on the download handler's text when logging.

Also, you'll need to be aware of any whitespace you might be missing, after assigning the download handler's text to a string, dump out the length and compare that to the length of the string to which you are doing a compare. If there is any trailing whitespace, for example, it might not be evident. If there is whitespace, trimming the received string may help you there before doing the comparison.

[Edit: balancing parentheticals]

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 gadashi12 · May 04, 2019 at 10:51 AM 0
Share

Thank you for the reply. It was in fact a problem with trailing whitespaces! It is weird because I am echoing "0 results" from the php script so why another whitespace is inserted, I don't know... But now I know what was wrong :)

avatar image JDelekto gadashi12 · May 04, 2019 at 11:04 AM 0
Share

Did you find out exactly what whitespace was trailing? Was it an actual space character (ASCII 32) or was it perhaps a transmitted carriage return, line feed (newline) or carriage return/line feed pair (ASCII 13, and 10 respectively)? If you used a construct (I'm not well versed in PHP) which did something like a "print line" ins$$anonymous$$d of a "print" and flushed the buffer to send to your client, the "print line" may add one (or a combination) of those two characters which one won't see visibly.

avatar image gadashi12 · May 04, 2019 at 06:19 PM 0
Share

I think it was an actual whitespace. I did not check the ASCII of it but I added some text after that and it was just seperated by a space.

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

150 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 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 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 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 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 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 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 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 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

How to stop WWW from changing request url? 1 Answer

Simple networking - Sending string over network? 1 Answer

Sync player name (Networking) 1 Answer

Double If condition syntax ? 1 Answer

More like a bulletin than chat box 0 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