读取汉字拼音首字母的程序

       public static string GetGBKPhoneticism(string character)
        {
            byte[] array = new byte[2];
            char[] nowchar = character.ToCharArray();
            int first = 0;
            int second = 0;
            int chrasc = 0;
            string sRet = "";
            for (int i = 0; i < nowchar.Length; i++)
            {
                array = System.Text.Encoding.Default.GetBytes(nowchar[i].ToString());
                first = (short)(array[0]);
                if (array.Length == 1)
                {
                    sRet += nowchar[i];
                    continue;
                }
                else
                {
                    second = (short)(array[1]);
                }
                chrasc = first * 256 + second;
                if ((chrasc >= 45217) && (chrasc <= 45252))
                {
                    sRet +=  "A";
                }
                else if ((chrasc >= 45253) && (chrasc <= 45760))
                {
                    sRet +=  "B";
                }
                else if ((chrasc >= 45761) && (chrasc <= 46317))
                {
                    sRet +=  "C";
                }
                else if ((chrasc >= 46318) && (chrasc <= 46825))
                {
                    sRet +=  "D";
                }
                else if ((chrasc >= 46826) && (chrasc <= 47009))
                {
                    sRet +=  "E";
                }
                else if ((chrasc >= 47010) && (chrasc <= 47296))
                {
                    sRet +=  "F";
                }
                else if ((chrasc >= 47297) && (chrasc <= 47613))
                {
                    sRet +=  "G";
                }
                else if ((chrasc >= 47614) && (chrasc <= 48118))
                {
                    sRet +=  "H";
                }
                else if ((chrasc >= 48119) && (chrasc <= 49061))
                {
                    sRet +=  "J";
                }
                else if ((chrasc >= 49062) && (chrasc <= 49323))
                {
                    sRet +=  "K";
                }
                else if ((chrasc >= 49324) && (chrasc <= 49895))
                {
                    sRet +=  "L";
                }
                else if ((chrasc >= 49896) && (chrasc <= 50370))
                {
                    sRet +=  "M";
                }

                else if ((chrasc >= 50371) && (chrasc <= 50613))
                {
                    sRet +=  "N";
                }
                else if ((chrasc >= 50614) && (chrasc <= 50621))
                {
                    sRet +=  "O";
                }
                else if ((chrasc >= 50622) && (chrasc <= 50905))
                {
                    sRet +=  "P";
                }
                else if ((chrasc >= 50906) && (chrasc <= .51386))
                {
                    sRet +=  "Q";
                }
                else if ((chrasc >= 51387) && (chrasc <= 51445))
                {
                    sRet +=  "R";
                }
                else if ((chrasc >= 51446) && (chrasc <= 52217))
                {
                    sRet +=  "S";
                }
                else if ((chrasc >= 52218) && (chrasc <= 52697))
                {
                    sRet +=  "T";
                }
                else if ((chrasc >= 52698) && (chrasc <= 52979))
                {
                    sRet +=  "W";
                }
                else if ((chrasc >= 52980) && (chrasc <= 53640))
                {
                    sRet +=  "X";
                }
                else if ((chrasc >= 53689) && (chrasc <= 54480))
                {
                    sRet +=  "Y";
                }
                else if ((chrasc >= 54481) && (chrasc <= 55289))
                {
                    sRet +=  "Z";
                }
                else sRet += nowchar[i];
            }

            return sRet.ToUpper();

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值