Re: How do I make a string comparison switch?

From: Adam (NOTFORSPAM.a_szczeblewski_at_poczta.onet.pl)
Date: 05/31/04


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



Relevant Pages

  • Re: stereo amp cleaning
    ... lubricating cleaner makes all go smoothly. ... plus a switch to reverse the channels between pre-ampandamp. ... giant expensive output transistors. ... one that's off or b) start swapping electrolytic capacitors from channel to ...
    (sci.electronics.repair)
  • RE: Switching NIC Cards
    ... internal switch and connect the internal NIC to external Switch ... This newsgroup only focuses on SBS technical issues. ... you may want to contact Microsoft CSS directly. ...
    (microsoft.public.windows.server.sbs)
  • Re: Virtual Memory Minimum Too Low
    ... The /3GB switch changes the way the 4GB virtual address space is split up. ... Microsoft CSS Online Newsgroup Support ... This newsgroup only focuses on SBS technical issues. ... When opening a new thread via the web interface, we recommend you check the ...
    (microsoft.public.windows.server.sbs)
  • Re: formatting numeric data from Access merged into a Word table
    ... "Heaven knows why" tells me there's a cleaner way to do this whole thing. ... mergefield in you mailmerge template. ... delete everything between 'MyData' and the closing field brace ... will I have to make these switch changes in the table in Word ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Safe to use WD40 as switch or potentiometer cleaner?
    ... switch by just moving it thru its range 5-10 or so times. ... kinds of pots and switches over the years and this method just doesn't last ... tuner cleaner sprays using a plastic extender tube. ... if the pot or switch shaft originally had grease on it and the spray ...
    (sci.electronics.repair)