List<string> Custom Sorting

asp.net, c#, list, sorting

Solution

If you want a simple way of doing it, and you expect your array to not change too much:

EDITED 11/30/2012

List.Sort((x, y) => x.Substring(x.IndexOf(">") + 1, 1).CompareTo(y.Substring(y.IndexOf(">") + 1, 1)));

Problem

I currently have a `List<string>` object that stores following HTML strings, mainly the URLs, e.g. ``` List[0] = "<a href='#' id='1'>Banana</a>"; List[1] = "<a href='#' id='2'>Orange</a>"; List[2] = "<a href='#' id='3'>Apple</a>"; List[3] = "<a href='#' id='4'>Mango</a>"; ... ``` And, when I sort the `List<string>` object, by doing `URLList.Sort(); (assume that`URLList`object has been instantiated.)`, it gives such order, Banana=>Orange=>Apple=>Mango, which is not exactly what I wanted. I'd like to have it sorted based on the alphabetical order of these fruit, which is like Apple=>Banana=>Mango=>Orange. So how can I achieve this custom sorting? Any suggestions? Thanks.

Original source