How to extract numbers from string(nvarchar
) in LINQ Query.
For example: SEQ01
, I want to take only the number (01
) and execute order by on it.
The problem with default string order by is that it orders it 1, 10, 100, 2, 3 etc..
I have tried the multiple methods to handle this, TryParse
, Convert.ToInt32
does not work since it has part which is not a number.
Sorting first by length than by the string still wont work in my case since the string part (SEQ
) can be changed and has variable length.
We are using .NET Core 3.1 so SqlFunctions are not present.
And the ordering must be on database side, ordering in memory is not performant enough for us.