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:

            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

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]