Guest User

Untitled

a guest
Dec 11th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. string[] myNiceSort(string[] items)
  2. {
  3. string[] prefixes = string[] {"a", "the", "is"};
  4. char[] charsToTrim = { ' ', ',', '\t', '.'};
  5.  
  6. Array.Sort(items, delegate(string a, string b) {
  7.  
  8. // two following chunks, one can put in some external function
  9. a = a.ToLower();
  10. int pa = a.IndexOfAny(charsToTrim);
  11. if (pa>0) {
  12. if (prefixes.Contains( a.Substring(0, pa) )) {
  13. // clean leading whitespaces
  14. a = a.Substring(pa).TrimStart(charsToTrim);
  15. }
  16. }
  17.  
  18. b = b.ToLower();
  19. int pb = b.IndexOfAny(charsToTrim);
  20. if (pb>0) {
  21. if (prefixes.Contains( b.Substring(0, pb) )) {
  22. // clean leading whitespaces
  23. b = b.Substring(pb).TrimStart(charsToTrim);
  24. }
  25. }
  26.  
  27. return a.CompareTo(b);
  28. });
  29.  
  30. return items;
  31. }
Add Comment
Please, Sign In to add comment