Search This Blog

Thursday, 5 May 2022

Alphanumeric Sorting using LINQ C#

public static string PadNumbers(string input)
{
     return Regex.Replace(input, "[0-9]+", match => match.Value.PadLeft(10, '0'));
}
string[] alphaNumericList = new string[] 
{ 
    "Field1", "Field11","Field2", "Field11","Field10", "Field1", "Field2", "Field11" 
};
var result = alphaNumericList.OrderBy(x => PadNumbers(x));


 

No comments:

Post a Comment

Popular Posts