Re: Switch on Strings



On Sat, 14 Jan 2006 00:32:18 GMT, fb <fb@xxxxxxxxx> wrote, quoted or
indirectly quoted someone who said :

>
>myColor is a String being read in from an HTML file PARAM line.
>The above code doesn't work, because switch doesn't work with strings.
>So I was wondering how else I can do this...

you do it with enums. See http://mindprod.com/jgloss/enum.html

You convert your switch string to an enum with valueOf and use enum
constants instead of strings on your case labels.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.



Relevant Pages

  • Re: Reflection and variable selection? Late binding?
    ... If your variables are all integers (or any of the supported base Types for Enums) then use an Enum as in my second example. ... If your variables are other Types such as strings or complex Types then you should use the switch statement. ... when each case is doing something very similar: going from string "x" to ...
    (microsoft.public.dotnet.framework)
  • 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: Have some problem with enum and string
    ... I have below a for loop and a switch in the for loop. ... I have also a enum called colBlowStep with some values. ... I know I can use string but I rather want to use enum. ...
    (microsoft.public.dotnet.languages.csharp)
  • 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: 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)