-2

This is a really simple question, yet somehow it's got me thinking. I have opening hours formatted in this way: [MO,TU:0800-1230,1300-1700;WE:0800-1230;TH:0800-1230,1400-1700;FR:0800-1230,1300-1500;SA,SU:0800-1500]. The string can have one time entry per day, but it doesn't have to, as you can see.

I need to extract each day and save it to the corresponding day field field (which is just a String like HH:mm-HH:mm) of an OpeningHrs class. What would be the best way to go at this? I'm not looking for code, just a suggestion on what the cleanest way would be to achieve my goal, bcause all solutions going through my head seem needlessly complicated.

  • Split the string by ; to separate your different schedules, then split the obtained string by : to separate the days from the time entries, and finally split the new strings by , to get each day and each time entry. – Vladimir Stanciu Sep 03 '20 at 13:08
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Sep 03 '20 at 13:10
  • Or, better yet, don't use regex. – Christopher Schneider Sep 03 '20 at 13:15

1 Answers1

0

It's well formatted. There's no regex needed. Split by ; to start with. Then split those results by :. From there you're left with two comma separated values where index 0 will be days of week, and index 1 will be store hours, which you'll split each by ,.

Christopher Schneider
  • 3,289
  • 2
  • 22
  • 34