The last entry must always be an Off.
The sequence can not be an Off/Off, Off/On, On/On. If my array has an invalid entry I want to do something. Can someone assist me.
Correct Array Below:
| TStamp | State |
| 1:05 | On |
| 1:10 | Off |
| 1:15 | On |
| 1:20 | Off |
| 1:25 | On |
| 1:30 | Off |
Wrong Array Below:
| TStamp | State |
| 1:05 | On |
| 1:10 | On |
| 1:15 | On |
| 1:20 | Off |
| 1:25 | On |
| 1:30 | Off |

VulpesRank #55 · 29.2K reputationPosted Jun 25, 2013, 6:56 AM EDT
It can, of course, be easily turned into a one-liner if that's what's needed:
bool isValid = Regex.IsMatch (String.Join("", state), "^(OnOff)+$");
Hemant SrivastavaRank #581 · 4.2K reputationPosted Jun 25, 2013, 6:51 AM EDT
David SmithRank #999 · 2K reputationPosted Jun 25, 2013, 11:10 AM EDT
Vuples, I left something out. The State Array will also contain a tStamp and State concatenated together. The format will like this below.
ArrayElement[0]= "1:05:00 PM 06/25/2013 On"
ArrayElement[1]= "1:10:00 PM 06/25/2013 Off"
ArrayElement[2]= "1:15:00 PM 06/25/2013 On"
ArrayElement[3]= "1:20:00 PM 06/25/2013 Off"
ArrayElement[4]= "1:25:00 PM 06/25/2013 On"
ArrayElement[5]= "1:30:00 PM 06/25/2013 Off"
So how to modify regex and logic to account for the entire string logic base upon the array above
Lastly,
Since the goal is to really add up the time an object has been off, I need to add in some logic to do something if a cycle or element gets corrupt. A complete cycle is On/Off. At the moment your function is only validating whether is the Array has a complete On/Off Cycle.
Let me give an example of an invalid array. The array is been initialized from an input file.
Invalid Array Example: ArrayElement[2] data can't be calculated because, the timestamp is not in range, if that make sense. So if a case like that were to happen, I want to do something, so I am trying to come up with a linq that will account for a perfect sequence and Perfect timestamp sequence.
ArrayElement[0]= "1:05:00 PM 06/25/2013 On"
ArrayElement[1]= "1:10:00 PM 06/25/2013 Off"
ArrayElement[2]= "1:15:00 PM 05/25/2013 On"
ArrayElement[3]= "1:20:00 PM 06/25/2013 Off"
ArrayElement[4]= "1:25:00 PM 06/25/2013 On"
ArrayElement[5]= "1:30:00 PM 06/25/2013 Off"
VulpesRank #55 · 29.2K reputationPosted Jun 25, 2013, 1:07 PM EDT