Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string[] myNiceSort(string[] items)
- {
- string[] prefixes = string[] {"a", "the", "is"};
- char[] charsToTrim = { ' ', ',', '\t', '.'};
- Array.Sort(items, delegate(string a, string b) {
- // two following chunks, one can put in some external function
- a = a.ToLower();
- int pa = a.IndexOfAny(charsToTrim);
- if (pa>0) {
- if (prefixes.Contains( a.Substring(0, pa) )) {
- // clean leading whitespaces
- a = a.Substring(pa).TrimStart(charsToTrim);
- }
- }
- b = b.ToLower();
- int pb = b.IndexOfAny(charsToTrim);
- if (pb>0) {
- if (prefixes.Contains( b.Substring(0, pb) )) {
- // clean leading whitespaces
- b = b.Substring(pb).TrimStart(charsToTrim);
- }
- }
- return a.CompareTo(b);
- });
- return items;
- }
Add Comment
Please, Sign In to add comment