Case with '
mpullin
Posts: 949
Let's say I have some rooms, named the following:
Theater
John's Room
Media Room
Now let's say I want to do a switch/case block to take an action depending on the room name. How do I deal with the apostrophe? This won't compile:
Anyone have any ideas for making this work? I realize one could just use select/active, but I want to know if it is possible to do it with switch/case. Would make a nice brain bender for an 11 am coffee break.
Theater
John's Room
Media Room
Now let's say I want to do a switch/case block to take an action depending on the room name. How do I deal with the apostrophe? This won't compile:
switch(sRoom[sTP_Session[GET_LAST(arrTP)].currRoom].name){ case "'Theater'": SEND_COMMAND vdvAMP_THEATER, "'SURROUND?'"; SEND_COMMAND BUTTON.INPUT.DEVICE, 'PPON-Surround_Mode'; case "'John',$27,'s Room'": SEND_COMMAND vdvAMP_JOHN_ROOM, "'SURROUND?'"; SEND_COMMAND BUTTON.INPUT.DEVICE, 'PPON-Surround_Mode'; case "'Media Room'": SEND_COMMAND vdvAMP_MEDIA_ROOM, "'SURROUND?'"; SEND_COMMAND BUTTON.INPUT.DEVICE, 'PPON-Surround_Mode'; default: break; // other rooms }
Anyone have any ideas for making this work? I realize one could just use select/active, but I want to know if it is possible to do it with switch/case. Would make a nice brain bender for an 11 am coffee break.
0
Comments
What if you just added the hex asci chars up and did a case by that?
john's = $64,$6F,$68,$6E,$27,$73.
add them up before going into the switch / case
(I know, I'm getting way to far in...)
Actually this might be a good situation for using a Select Active rather than a Switch Case.
Why use text at all? You should have a constant for each room that is an integer and then check that. You are asking for trouble (and already received some) using text to do this.
The escape for ' is ' not ".
Paul