The “Matches” Activity creates an IEnumerable of all chapter numbers found in a document. As sometimes a mismatch occurs, it would be nice to check if the chapter numbers are continuously increasing. For example:
3.21.1.
3.21.2. OK
3.16. XXXXXX → should be deleted
3.21.3 OK
4. OK
4.1. OK
4.1.1. OK
2. XXXXXXXX → should be deleted
I would suggest to check the IEnumerable element per element to gurantee, that each number (between dots) is either increased by one (3.21.1 → 3.21.2), created (4. → 4.1.) or gone (3.21.3 → 4.). But how to do that? Using a Switch combined with another match activity for each number between dots? I would like to keep it as simple as possible.
I think this is a “simple” exercise that will wind up being trickier than you expect. Good that you’ve identified the use cases.
First, I would have a “last valid” and “current” variables, as string arrays and a bool, IsValid
Cases
LastValid = IEnumerable(0).tostring.split // initialize first value. I would add in some logic to make sure that each input is at least somewhat valid before proceeding. If first variable fails, others will fail.
For Each IENumerable
If counter = 0, next // easiest logic since
Current = IEnumerable.tostring.split(‘.’)
Current.length = LastValid.length (1st scenario)
** Set IsValid to a comparison between the last elements in the array
Current.length > LastValid.length (2nd scenario)
** Set IsValid to see if the 2nd to last element of the arrays are equal
Current.length < lastValid.length (3rd Scenario)
** Set IsValid to see if last element of Current is > the same element in LastValid
If (IsValid)
Keep
LastValid = Current
Else
Delete
Would be the very rough pseudocode. You’ll need to look up how to use the .net system.array methods to make this work though. Also you will need more logic if you want to deal with skipped chapters/subchapters (note in some cases you won’t know if you skipped a chapter/subchapter)
I laid out the logic I think is needed (based on your problem description), but there are a number of .net details needed to solve. Those can be pretty tricky. Good luck!