How to convert System.Text.RegularExpressions.MatchCollection to Integer?

I have a variable called Matches that is the output of Regex.Matches(StrReader.ReadToEnd(),"/Type\s*/Page[^s]")

This is a regex to get the number of pages in a pdf file

How could I convert this to an integer?

You can’t. MatchCollection is, well, a collection. Not a single value.


Number is between words ‘Type’ and ‘Page’?
If so capture that number into group (using brackets) - regex should look like this: “/Type(\s*)/Page[^s]”.
Now for example ‘/Type 15/Page’ your first matching group will be ‘15’.
To Convert expression into integer try something like this:


where (0) means first match in collection,
Groups(1) menas first group (brackets in regex)

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