|
Author |
Topic: String.substring == error (Read 371 times) |
|
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://"))...
|
|
|
|
|