FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   String comparison
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: String comparison  (Read 243 times)
ydur75
Guest
Email
String comparison
« on: May 18th, 2004, 7:32pm »

How I can compare a string variables with a string value. i.e. is correct do this?:
String name="sam";
if (name=="sam")
{
}
 
Thanks
Rudy
 
Sprak

20070562007056 WWW
Re: String comparison
« Reply #1 on: May 18th, 2004, 8:58pm »

Best way to find out is to try it You are correct however.
 
justo


Re: String comparison
« Reply #2 on: May 18th, 2004, 9:41pm »

the == operator will only return true when comparing two object when they are the same object...ie (name == name) will always be true but (name == "sam") will always be false...because "sam" is implicitly another string object. also,
 
Code:
String name = "sam";
String name2 = name;
if (name == name2) { //will be true because they point to the same object
}

 
 
what you want is name.equals("sam")...it will be true when the strings are the same.
 
ydur75
Guest
Email
Re: String comparison
« Reply #3 on: May 19th, 2004, 11:46am »

Thank you very much justo.
Rudy
 
Pages: 1 

« Previous topic | Next topic »