小功能 获取一段汉字的拼音首字母

ContractedBlock.gifExpandedBlockStart.gifCode
 1 internal sealed class program
 2ExpandedBlockStart.gifContractedBlock.gif    {
 3ExpandedSubBlockStart.gifContractedSubBlock.gif        public static void Main() {
 4            Console.WriteLine(ChineseToPYAbbreviation("你好,我就要拼音首字母").ToUpper());//NH*WJYPYSZM
 5            Console.ReadLine();
 6        }

 7        public static string ChineseToPYAbbreviation(string str)
 8ExpandedSubBlockStart.gifContractedSubBlock.gif        {
 9            string tempStr = "";
10            foreach (char c in str)
11ExpandedSubBlockStart.gifContractedSubBlock.gif            {
12                if ((int)c >= 33 && (int)c <= 126)
13ExpandedSubBlockStart.gifContractedSubBlock.gif                {//字母和符号原样保留
14
15                    tempStr += c.ToString();
16                }

17                else
18ExpandedSubBlockStart.gifContractedSubBlock.gif                {//累加拼音声母
19                    tempStr += GetPYChar(c.ToString());
20                }

21            }

22            return tempStr;
23        }

24ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//**//**//// 
25        /// 取单个字符的拼音声母
26        /// 
27        /// 要转换的单个汉字
28        /// 拼音声母

29        private static string GetPYChar(string c)
30ExpandedSubBlockStart.gifContractedSubBlock.gif        {
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'));
34
35            if (i < 0xB0A1return "*";
36            if (i < 0xB0C5return "a";
37            if (i < 0xB2C1return "b";
38            if (i < 0xB4EEreturn "c";
39            if (i < 0xB6EAreturn "d";
40            if (i < 0xB7A2return "e";
41            if (i < 0xB8C1return "f";
42            if (i < 0xB9FEreturn "g";
43            if (i < 0xBBF7return "h";
44            if (i < 0xBFA6return "j";
45            if (i < 0xC0ACreturn "k";
46            if (i < 0xC2E8return "l";
47            if (i < 0xC4C3return "m";
48            if (i < 0xC5B6return "n";
49            if (i < 0xC5BEreturn "o";
50            if (i < 0xC6DAreturn "p";
51            if (i < 0xC8BBreturn "q";
52            if (i < 0xC8F6return "r";
53            if (i < 0xCBFAreturn "s";
54            if (i < 0xCDDAreturn "t";
55            if (i < 0xCEF4return "w";
56            if (i < 0xD1B9return "x";
57            if (i < 0xD4D1return "y";
58            if (i < 0xD7FAreturn "z";
59            return "*";
60        }

61    }
 
62

转载于:https://www.cnblogs.com/hl0071/articles/1383167.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值