Re: How do I make a string comparison switch?
From: Adam (NOTFORSPAM.a_szczeblewski_at_poczta.onet.pl)
Date: 05/31/04
- Next message: Roedy Green: "Re: How do I make a string comparison switch?"
- Previous message: Andrew Thompson: "Re: no applications"
- In reply to: Panama Red: "Re: How do I make a string comparison switch?"
- Next in thread: Roedy Green: "Re: How do I make a string comparison switch?"
- Reply: Roedy Green: "Re: How do I make a string comparison switch?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 31 May 2004 08:35:53 +0200
"Panama Red" <complaintdepartment2002@yahoo.com> wrote in message
news:6e3qo1-jt4.ln1@ralph.homelinux.net...
> 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 )
Somwhere in that newsgroup (or maybe c.l.j.programmer)
I've seen something like
int hash = request.hashCode();
switch(hash){
case "HELLO".hashCode():
...
etc.
But I'm not sure about the details, you have to
google it up.
Adam
- Next message: Roedy Green: "Re: How do I make a string comparison switch?"
- Previous message: Andrew Thompson: "Re: no applications"
- In reply to: Panama Red: "Re: How do I make a string comparison switch?"
- Next in thread: Roedy Green: "Re: How do I make a string comparison switch?"
- Reply: Roedy Green: "Re: How do I make a string comparison switch?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|