Re: How do I make a string comparison switch?
From: Chris Smith (cdsmith_at_twu.net)
Date: 05/30/04
- Next message: Panama Red: "Re: Begginner to java"
- Previous message: D. Beckham: "Doubly-Link List Setup????"
- In reply to: Panama Red: "How do I make a string comparison switch?"
- Next in thread: Panama Red: "Re: How do I make a string comparison switch?"
- Reply: Panama Red: "Re: How do I make a string comparison switch?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 30 May 2004 15:42:05 -0600
Panama Red wrote:
> I want to match a string against a series of different
> keywords... here is what Ive tried :
>
> switch(Request) {
>
> case Request.equals("HELLO"):
> // Write Results to Monitor
> logDisplay.append( "Results: HELLO BACK\n");
> break;
> }
>
> The compiler tells me I need an int, not a string ... so how do
> you do this common task?
if (Request.equals("HELLO"))
{
// Write Results to Monitor
logDisplay.append("Results: HELLO BACK\n");
}
If there are more possibilities, then:
else if (Request.equals("GOODBYE"))
{
...
}
else if (Request.equals("THANKYOU"))
{
...
}
and so forth.
Incidentally, it could trip up people who are trying to help you if you
use bad variable names in posts to public newsgroups. The practically-
universal Java naming convention is to begin variable names with a
lower-case letter (for example, request instead of Request) -- unless
they are constants, in which case you'd use all-caps.
-- www.designacourse.com The Easiest Way to Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
- Next message: Panama Red: "Re: Begginner to java"
- Previous message: D. Beckham: "Doubly-Link List Setup????"
- In reply to: Panama Red: "How do I make a string comparison switch?"
- Next in thread: Panama Red: "Re: How do I make a string comparison switch?"
- Reply: Panama Red: "Re: How do I make a string comparison switch?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|