 |
Author |
Topic: String equality isn't consistent (Read 197 times) |
|
Crwth
|
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
|
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.
|
|
|
|
|