Re: How do I make a string comparison switch?
From: Panama Red (complaintdepartment2002_at_yahoo.com)
Date: 05/31/04
- Next message: Nicholas Pappas: "Re: Begginner to java"
- Previous message: Ryan Stewart: "Re: question on multidimensional array"
- In reply to: Chris Smith: "Re: How do I make a string comparison switch?"
- Next in thread: Adam: "Re: How do I make a string comparison switch?"
- Reply: Adam: "Re: How do I make a string comparison switch?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 30 May 2004 22:22:45 GMT
I believe it was Chris Smith who said...
> 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.
Ahh...so there is no way to do it with a switch (seems a little
cleaner with switch )
> 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.
yes, my mistake...thanks for the tip.
- Next message: Nicholas Pappas: "Re: Begginner to java"
- Previous message: Ryan Stewart: "Re: question on multidimensional array"
- In reply to: Chris Smith: "Re: How do I make a string comparison switch?"
- Next in thread: Adam: "Re: How do I make a string comparison switch?"
- Reply: Adam: "Re: How do I make a string comparison switch?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|