Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple String problems... 1

Status
Not open for further replies.

SWTpaul

Technical User
Nov 11, 2003
27
US
The ItmCls is retrieved from the previous page, and equals RRXXX.

String webCls = request.getParameter("ItmCls");
String itmCls = webCls.substring(0,2);

if (itmCls == "RR") {
<perform actions here>
} else {
<do this>
}

Some reason the condition will not test true. I have outputed itmCls on the web page to double check its value and it does equal RR. I then created a dummy var String test = "RR" and replaced itmCls with test in the condition and it worked. Am I missing something simple?
 
I usually define my variables as strings by casting the info that I pull in:
Code:
webCls = [b][COLOR=red]String([/color][/b]request.getParameter("ItmCls")[b][COLOR=red])[/color][/b];
itmCls = [b][COLOR=red]String([/color][/b]webCls.substring(0,2)[b][COLOR=red])[/color][/b];
I'm not sure that will make a huge difference in the outcome tho. Try throwing out some other debugging techniques like:

alert(itmCls.length); //make sure it's 2
alert("-" + itmCls + "-"); //easy way to check for any preceeding or succeeding spaces

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
This is a Java question and the answer is change:

itmCls == "RR"

to

itmCls.equals("RR")

'hope this helps.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top