I want to order an array containing numbers and letters in an ascending order the values are stored as a string in a DB.
This is the list I have
4B
1A
1
1B
2
4C
4
and want them to order like this where numbers are ascending followed by letters alphabetically.
1
1A
1B
2
4
4B
4C
So far I tried
allScenes.OrderBy(x => Convert.ToInt32(x.SceneNumber)).ToList()
and
allScenes.OrderBy(x => Convert.int.parse(x.SceneNumber)).ToList()
but both don't work because of the letters after the number. Any idea how I can make this work?
Given your example data where the first number is always a single digit:
If you can possibly have multi-digit numbers, please provide them and where you want them in the sort order.
This is one way to sort multiple digit numbers:
Results:
The database may not be able to convert the LastIndexOfAny function to something SQL-like, so you may need to do an .ToList() before the .OrderBy():