Advertisement
clockworksaint

C# Pinyin Collation Test

Jun 3rd, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5. using System.Text;
  6.  
  7. class CollationTest
  8. {
  9.     class TestChar
  10.     {
  11.         public char Value { get; set; }
  12.         public string Name { get; set; }
  13.         public override string ToString()
  14.         {
  15.             return String.Format("{0} '{1}' ('\\u{2:X4}')", Name, Value, (int)Value);
  16.         }
  17.     }
  18.     static void Main(string[] args)
  19.     {
  20.         string cultureName =
  21.             (args.Length == 0) ? "zh-Hans" :
  22.             (args[0] == "invariant") ? "" :
  23.             args[0];
  24.         var chars = new List<TestChar> {
  25.             new TestChar { Value = '\u8303', Name = "fan" },
  26.             new TestChar { Value = '\u5999', Name = "miào" },
  27.             new TestChar { Value = '\u5DE7', Name = "qiao " },
  28.             new TestChar { Value = '\u8EAB', Name = "shen " },
  29.             new TestChar { Value = '\u793A', Name = "shì " },
  30.             new TestChar { Value = '\u4EE5', Name = "yi " },
  31.             new TestChar { Value = '\u5219', Name = "zé " },
  32.             new TestChar { Value = '\u4F5C', Name = "zuò " },
  33.         };
  34.         var cinfo = new CultureInfo(cultureName);
  35.         Console.WriteLine("{0}: {1}", cinfo.Name, cinfo.DisplayName);
  36.         chars.Sort((a,b)=>String.Compare(a.Value.ToString(),b.Value.ToString(),true,cinfo));
  37.         foreach (var item in chars)
  38.         {
  39.             Console.WriteLine(item);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement