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.substring == error
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: String.substring == error  (Read 371 times)
rgovostes

rgovostes
String.substring == error
« on: Oct 16th, 2004, 8:40pm »

Code:
String url = "http://www.google.com";
if(url.substring(0, 7) == "http://") println("Starts with http://");

 
Nothing is printed if you execute the above.
 
Code:
String url = "http://www.google.com";
String http = url.substring(0, 7);
if(url.substring(0, 7) == http) println("Starts with http://");

 
That doesn't work either.
 
liminal


Re: String.substring == error
« Reply #1 on: Oct 18th, 2004, 6:33am »

You need to use the equals method on String. Using the '==' operator does an indentity comparison on the objects themselves. Since they're different String objects, it returns false.
 
So your code should be:
 
if (url.substring(0, 7).equals("http://"))...
 
Pages: 1 

« Previous topic | Next topic »