Code 1 internal sealed class program 2 { 3 public static void Main() { 4 Console.WriteLine(ChineseToPYAbbreviation("你好,我就要拼音首字母").ToUpper());//NH*WJYPYSZM 5 Console.ReadLine(); 6 } 7 public static string ChineseToPYAbbreviation(string str) 8 { 9 string tempStr = "";10 foreach (char c in str)11 {12 if ((int)c >= 33 && (int)c <= 126)13 {//字母和符号原样保留1415 tempStr += c.ToString();16 }17 else18 {//累加拼音声母19 tempStr += GetPYChar(c.ToString());20 }21 }22 return tempStr;23 }24 /**//**//**//// 25 /// 取单个字符的拼音声母26 /// 27 /// 要转换的单个汉字28 /// 拼音声母29 private static string GetPYChar(string c)30 {31 byte[] array = new byte[2];32 array = System.Text.Encoding.Default.GetBytes(c);33 int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));3435 if (i < 0xB0A1) return "*";36 if (i < 0xB0C5) return "a";37 if (i < 0xB2C1) return "b";38 if (i < 0xB4EE) return "c";39 if (i < 0xB6EA) return "d";40 if (i < 0xB7A2) return "e";41 if (i < 0xB8C1) return "f";42 if (i < 0xB9FE) return "g";43 if (i < 0xBBF7) return "h";44 if (i < 0xBFA6) return "j";45 if (i < 0xC0AC) return "k";46 if (i < 0xC2E8) return "l";47 if (i < 0xC4C3) return "m";48 if (i < 0xC5B6) return "n";49 if (i < 0xC5BE) return "o";50 if (i < 0xC6DA) return "p";51 if (i < 0xC8BB) return "q";52 if (i < 0xC8F6) return "r";53 if (i < 0xCBFA) return "s";54 if (i < 0xCDDA) return "t";55 if (i < 0xCEF4) return "w";56 if (i < 0xD1B9) return "x";57 if (i < 0xD4D1) return "y";58 if (i < 0xD7FA) return "z";59 return "*";60 }61 } 62 转载于:https://www.cnblogs.com/hl0071/articles/1383167.html