I have a flyerPages list which I pull from my database into a list as seen here:
var flyerPages = _flyerPageRepository.FindAllPagesAsync(_flyerId);
I then do the following to order them:
flyerPages.OrderBy(x => x.DocumentName);
This is my result:
DE9320_1_1_.txt
DE9320_1_2_.txt
DE9320_10_1_.txt
DE9320_10_2_.txt
DE9320_11_1_.txt
DE9320_11_2_.txt
DE9320_4_1_.txt
DE9320_4_2_.txt
DE9320_5_1_.txt
DE9320_5_2_.txt
DE9320_6_1_.txt
DE9320_6_2_.txt
DE9320_7_1_.txt
DE9320_7_2_.txt
DE9320_8_1_.txt
DE9320_8_2_.txt
The first number in the filename represents the page number the second represents the part of the page so DE9320_1_1_.txt
is page 1 part 1, it can also be shown as DE9320_01_1_.txt
etc. Sometimes there is only one part and it is shown as DE9320_1.txt
or DE9320_01.txt
.
Because I am using a string the 10th page comes before the second. Now of course I can just grab the numbers from the middle and sort them but I was wondering is there a way to use only a linq statement to achieve this? If not what would be an easier method then going through each string and extracting the numbers from the middle?