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 equality isn't consistent
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: String equality isn't consistent  (Read 197 times)
Crwth

WWW
String equality isn't consistent
« on: Oct 3rd, 2003, 4:48pm »

My apologies if this is covered elsewhere.  This is v.0065.
 
The following code
 
void setup() {
  String lines[]={"test"}, B;
  B=lines[0];
  if (B=="test") {
    println("B=='test'");
  } else {
    println("B!='test'");
  }
}
 
reports that B=='test', as expected.  This code
 
void setup() {
  String lines[]=loadStrings("list.txt"), B;
  B=lines[0];
  if (B=="test") {
    println("B=='test'");
  } else {
    println("B!='test'");
  }
}
 
reports that B!='test'.  Of course, using
 
if (B.equals("test")) {
 
works fine, but isn't intuitive to a non-Java programmer, and isn't documented.
 
--
  Wayne
 

--
Wayne
fry


WWW
Re: String equality isn't consistent
« Reply #1 on: Oct 3rd, 2003, 5:44pm »

ah, right..  
 
not really a bug (i'll move to the syntax section), but i'll make a note to try and figure out how to get this in the docs, since we don't spend much time talking about issues like this that we're leaving to java. especially in the case of strings, where comparisons are likely to cause some confusion for newer programmers.
 
Pages: 1 

« Previous topic | Next topic »