asp.net中文转换成拼音首字母

 private static string getPinYin(string text)
    {
        char pinyin;
        byte[] array;
        System.Text.StringBuilder sb = new System.Text.StringBuilder(text.Length);
        foreach (char c in text)
        {
            pinyin = c;
            array = System.Text.Encoding.Default.GetBytes(new char[] { c });

            if (array.Length == 2)
            {
                int i = array[0] * 0x100 + array[1];

                if (i < 0xB0A1) pinyin = c;
                else
                    if (i < 0xB0C5) pinyin = 'a';
                    else
                        if (i < 0xB2C1) pinyin = 'b';
                        else
                            if (i < 0xB4EE) pinyin = 'c';
                            else
                                if (i < 0xB6EA) pinyin = 'd';
                                else
                                    if (i < 0xB7A2) pinyin = 'e';
                                    else
                                        if (i < 0xB8C1) pinyin = 'f';
                                        else
                                            if (i < 0xB9FE) pinyin = 'g';
                                            else
                                                if (i < 0xBBF7) pinyin = 'h';
                                                else
                                                    if (i < 0xBFA6) pinyin = 'g';
                                                    else
                                                        if (i < 0xC0AC) pinyin = 'k';
                                                        else
                                                            if (i < 0xC2E8) pinyin = 'l';
                                                            else
                                                                if (i < 0xC4C3) pinyin = 'm';
                                                                else
                                                                    if (i < 0xC5B6) pinyin = 'n';
                                                                    else
                                                                        if (i < 0xC5BE) pinyin = 'o';
                                                                        else
                                                                            if (i < 0xC6DA) pinyin = 'p';
                                                                            else
                                                                                if (i < 0xC8BB) pinyin = 'q';
                                                                                else
                                                                                    if (i < 0xC8F6) pinyin = 'r';
                                                                                    else
                                                                                        if (i < 0xCBFA) pinyin = 's';
                                                                                        else
                                                                                            if (i < 0xCDDA) pinyin = 't';
                                                                                            else
                                                                                                if (i < 0xCEF4) pinyin = 'w';
                                                                                                else
                                                                                                    if (i < 0xD1B9) pinyin =

'x';
                                                                                                    else
                                                                                                        if (i < 0xD4D1)

                                                                                                            pinyin = 'y';
                                                                                                        else
                                                                                                            if (i < 0xD7FA)

                                                                                                                pinyin = 'z';
            }

            sb.Append(pinyin);
        }

        return sb.ToString();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值