c# ordering strings with different formats

Viewed 154

I have Licence plate numbers which I return to UI and I want them ordered in asc order:

So let's say the input is as below:

1/12/13/2
1/12/11/3
1/12/12/2
1/12/12/1

My expected output is:

1/12/11/3
1/12/12/1
1/12/12/2
1/12/13/2

My current code which is working to do this is:

var orderedData = allLicenceNumbers
   .OrderBy(x => x.LicenceNumber.Length)
   .ThenBy(x => x.LicenceNumber)
   .ToList();

However for another input sample as below:

4/032/004/2
4/032/004/9
4/032/004/3/A
4/032/004/3/B
4/032/004/11

I am getting the data returned as:

4/032/004/2
4/032/004/9
4/032/004/11
4/032/004/3/A
4/032/004/3/B

when what I need is:

4/032/004/2
4/032/004/3/A
4/032/004/3/B
4/032/004/9
4/032/004/11

Is there a better way I can order this simply to give correct result in both sample inputs or will I need to write a custom sort?

EDIT

It wont always be the same element on the string.

This could be example input:

2/3/5/1/A
1/4/6/7
1/3/8/9/B
1/3/8/9/A
1/5/6/7

Expected output would be:

1/3/8/9/A
1/3/8/9/B
1/4/6/7
1/5/6/7
2/3/5/1/A
3 Answers
Related