We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Alternet string comparison not working
Page Index Toggle Pages: 1
Alternet string comparison not working (Read 915 times)
Alternet string comparison not working
Jan 19th, 2010, 9:37am
 
I'm having a bit of a problem testing comparing Strings sent from client to server using the alternet library (forum doesn't allow me to link it, but look it up in google, if needed). Maybe it's just ignorance, but I truly can't figure it out for myself.

What I'm trying to do is have the server read a String sent from one of its clients, and compare it to any other data in the server, so that it can iterate through several possible actions. Well, things got tricky for some reason, and I can't have it returning true in the following statement:

Code:
void serverReceiveEvent(Server receivingServer, RemoteAddress client, String data) {
 if(data == "testing") {
   // do something
 }
}


I've printed the data in the server, after it's received, and made sure it is receiving exactly a string with the "testing" value. Still, it refuses to validate that statement, and I truly can't understand why.

Any ideas?

Thanks, Ed.
Re: Alternet string comparison not working
Reply #1 - Jan 28th, 2010, 7:15am
 
it's not that easy, but nearly:

Code:
 
if(data.equals("testing") == true) {
// do something
}


http://processing.org/reference/String_equals_.html
Re: Alternet string comparison not working
Reply #2 - Jan 28th, 2010, 12:15pm
 
It is in the reference, the FAQ and the troubleshooting pages... Smiley

Note: I prefer to omit equality on booleans:
Code:
if (data.equals("testing)) {
// ...
}
Somehow, looks more like English. Wink
Page Index Toggle Pages: 1