I’m looking for a way to easily calculate the number of pages in a page range such as the below:

Input: “1, 3-5, 9-11, 25”
(Desired) Output: 8 (the total number of pages within the range)

If there is any pre-built logic, that would be ideal. Otherwise I’d have to build from scratch.

Yoichi
(Yoichi)
October 15, 2021, 3:43am
#2
Hi,

How about the following expression?

```
yourString.Split(","c).Select(Function(s) if (s.Contains("-"),Int32.Parse(s.Split("-"c)(1).Trim)-Int32.Parse(s.Split("-"c)(0).Trim)+1,1)).Sum()
```

Regards,

1 Like

Aleem_Khan
(crazy bot)
October 16, 2021, 6:49pm
#4
could you please explain this string Input: “1, 3-5, 9-11, 25”
your query I appreciate

Hey @Aleem_Khan

That string shows the range

Aleem_Khan:

1, 3-5, 9-11, 25

1
3-5 means 3,4,5
9-11 means 9,10,11
25

This shows there are 8 elements in that range group.

Requirement from @Greg_Jacobson was to calculate those.

@Yoichi solutions is to check if there’s `-`

if yes split and calculate the difference (subtraction) of those and add 1 (5-3 = 2, if we add 1 then only it becomes 3, which is the correct number of elements in that range) , if not then simply count it as one.

system
(system)
closed
October 20, 2021, 6:12am
#6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.