Advertisement
clockworksaint

C# Pinyin Collation Test

Jun 3rd, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  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 = args.Length >= 1 ? args[0] : "zh-Hans";
  21.         var chars = new List<TestChar> {
  22.             new TestChar { Value = '\u8303', Name = "fan" },
  23.             new TestChar { Value = '\u5999', Name = "miào" },
  24.             new TestChar { Value = '\u5DE7', Name = "qiǎo " },
  25.             new TestChar { Value = '\u8EAB', Name = "shēn " },
  26.             new TestChar { Value = '\u793A', Name = "shì " },
  27.             new TestChar { Value = '\u4EE5', Name = "yǐ " },
  28.             new TestChar { Value = '\u5219', Name = "zé " },
  29.             new TestChar { Value = '\u4F5C', Name = "zuò " },
  30.         };
  31.         var cinfo = new CultureInfo(args[0]);
  32.         Console.WriteLine("{0}: {1}", cinfo.Name, cinfo.DisplayName);
  33.         chars.Sort((a,b)=>String.Compare(a.Value.ToString(),b.Value.ToString(),true,cinfo));
  34.         foreach (var item in chars)
  35.         {
  36.             Console.WriteLine(item);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement