Re: How do I make a string comparison switch?

From: Panama Red (complaintdepartment2002_at_yahoo.com)
Date: 05/31/04


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.



Relevant Pages

  • Re: Change Text to Memo
    ... Switch a given table field to Memo ... Function SwitchFieldType(sDb As String, sTableName As String, sFieldName ... Dim sSQL As String ... If Err.Number = 0 Then Exit Function ...
    (microsoft.public.access.modulesdaovba)
  • Re: proposal: reswitch
    ... > which levels of loops and/or switches and/or ... socket -server command ?-myaddr addr? ... You've got the quick-exit (break, no string), the fall-through to next ... -switch option), then it'd be the nth switch. ...
    (comp.lang.tcl)
  • Re: SRV
    ... I also play .12s for jazz, and can't bend those well at all. ... little as far as bending until you go to a wound string. ... When I switch from 10's to 9's, the 9's feel like limp rubber ...
    (alt.guitar)
  • Re: SRV
    ... I also play .12s for jazz, and can't bend those well at all. ... little as far as bending until you go to a wound string. ... When I switch from 10's to 9's, the 9's feel like limp rubber ...
    (alt.guitar)
  • Re: String-based Switch Request...
    ... Facilitate good callback programming design and modularization within GUI code ... When ever switch statements are used, they are typically over used being favour over polymorphism, which leads to brittle shoddy design. ... Use the string type-code as the Key and a Command or Strategy Object as the Value. ...
    (comp.lang.java.programmer)