I’m trying to sort a string array that contains numbers just by the letters so for example:
Original array = {"09Bananas", "Pears2", "Mangoes39Bad", "100Apples", "Mangoes38Good"}
Should become:
Sorted array = {"100Apples", "09Bananas", "Mangoes39Bad", "Mangoes38Good", "Pears2"}
However when I try to use Array.sort(original) it would come out like this:
{"09Bananas", "100Apples", "Mangoes38Good", "Mangoes39Bad", "Pears2"}
Is there an overload of Array.sort that would make it ignore numbers?
Thanks
Use
Array.Sort<T>(T[],IComparer<T>)overload, and skip digits before comparing strings.The LINQ expression
a.Where(char.IsLetter).ToArray()converts a string to an array of individual letters.