|
Author |
Topic: no match in == from array against string (Read 415 times) |
|
edwardgeorge
|
no match in == from array against string
« on: Mar 13th, 2003, 7:12pm » |
|
In some code i have, an incoming string is passed to a 'check' function to see if it is location info (in this example, there is also other types), this is defined by the second word. So, check() splits the string at " " (spaces) amd checks the second word(#1) against "Location", printing out the first word if it matches. else it prints out "no location info -" then the word it tried to match against "Location" then a forward slash(to make sure there is no trailing whitespace) see the following code... Code: void check(String l){ println("checking:"+l); String[] a=l.split(" "); if(a[1]=="Location"){ println("found:"+a[0]); }else{println("no location info -"+a[1]+"/");} } |
| heres what it results in Code: checking:TMale0 Location -300 200 400 no location info -Location/ |
| it seems it is not matching the second word in the array(in this case Location) against Location. Wha? What is going on? Thanks for any light you may shed. Ed_
|
Ed, Suppose, Nottingham, UK http://www.suppose.co.uk http://ed.suppose.co.uk
|
|
|
_martin Guest
|
Re: no match in == from array against string
« Reply #1 on: Mar 14th, 2003, 12:59am » |
|
Code:void check(String l){ println("checking:"+l); String[] a=l.split(" "); if(a[1]=="Location"){ println("found:"+a[0]); }else{println("no location info -"+a[1]+"/");} } |
|
|
|
|
|
_martin Guest
|
Re: no match in == from array against string
« Reply #2 on: Mar 14th, 2003, 1:01am » |
|
argh. sorry about the previous post. accidentally pressed the 'post' button. here... Code:void check(String l){ println("checking:"+l); String[] a=l.split(" "); if(a[1].equals("Location")){ println("found:"+a[0]); }else{println("no location info -"+a[1]+"/");} } |
|
|
|
|
|
_martin Guest
|
Re: no match in == from array against string
« Reply #4 on: Mar 15th, 2003, 6:25am » |
|
btw, s.split(String s2) is the java way of doing it. splitStrings(String s, String s2) is the processing way of doing it.
|
|
|
|
fry
|
Re: no match in == from array against string
« Reply #5 on: Mar 15th, 2003, 1:51pm » |
|
on Mar 15th, 2003, 6:25am, _martin wrote:btw, s.split(String s2) is the java way of doing it. splitStrings(String s, String s2) is the processing way of doing it. |
| yeah, and i'd remove splitStrings() except that split() is only available in jdk 1.4, which isn't running in most browsers (or at all on macos9).
|
|
|
|
|