c# - Linq - get max of string that ends with an integer -


this question has answer here:

i'm trying max of string column such - a1 a2 a3 ...

but when max number 10 or above - linq returns a9 max. why?

how solve this?

the code-

from d in db.documents.orderbydescending(d => d.number) (.....) select d.number) .firstordefault(); 

thanks in advance!

you cant normal linq, if want compare alphanumeric values, should this,

static void main(string[] args)         {             list<string> vals = new list<string>();             vals.add("a1");             vals.add("a11");             vals.add("a41");             vals.add("a13");             vals.add("a12");             vals.add("a9");             var result = vals.orderbydescending(x => ordernumbers(x));         }         public static string ordernumbers(string input)         {             return regex.replace(input, "[0-9]+", match => match.value.padleft(10, '0'));         } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -