Advertisement
Guest User

Untitled

a guest
Sep 12th, 2010
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1.  static string ReplaceNoise(string input)
  2.         {
  3.             string[] noise = new string[] { "the", "an", "a" };
  4.  
  5.             foreach (string n in noise)
  6.             {
  7.                 if (input.ToLower().StartsWith(n))
  8.                 {
  9.                     return input.Substring(n.Length).Trim();
  10.                 }
  11.             }
  12.  
  13.             return input;
  14.         }
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.  
  19.             List<Book> schools = new List<Book>{
  20.                     new Book{ ID=9, Title="The Nines"},                                                    
  21.                     new Book{ ID=6, Title="A Six Company Strategy"},
  22.                     new Book{ ID=3, Title="An Age of Three"},
  23.                     new Book{ ID=2, Title="Two's Company"},
  24.                     new Book{ ID=709, Title="The Sevens"}
  25.             };
  26.  
  27.  
  28.             //foreach (var item in schools.Select(x => new { NewTitle = ReplaceNoise(x.Title) }).OrderBy(n => n.NewTitle))
  29.             foreach (var item in schools.OrderBy(n => ReplaceNoise(n.Title)))
  30.             {
  31.                 Console.WriteLine(item.Title);
  32.             }
  33.  
  34.  
  35.             Console.ReadLine();
  36.  
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement