Switch case using strings. Is it possible?

Hi all.
Take a look at the code below:


  switch (day_ofWeek) // Global String variable
  {
   case "MONDAY":
   //do something
   break;
   case  "TUESDAY":
   // do another thing
   break; 

//Continue to SUNDAY
  }

This fails with ' switch quantity not an integer'.

So what is the best approach to compare all 7 days of the week?
Is an if statement the only way?
Thank you very much.

Regards

why do you use week day names? use numbers or enum

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

Not behind a PC but if not mistaken the usual day of week is a numeric value from 0 .. 6, so use that. Or an enum as mentioned by @Juraj.

Hi all.
I feel really stupid now! :blush:
I should have thought about this.
Regards.

Many of us have fallen into that kind of thing where we think "it can only be done this way" and so we do not try to think of other ways to do it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.