博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C# 给中文加字母

Posted on 2008-05-08 17:05  linFen  阅读(492)  评论(0编辑  收藏  举报

public string getSpell(string cn)
        {

            byte[] arrCN = Encoding.Default.GetBytes(cn);
            if (arrCN.Length > 1)
            {
             


                if (cn.CompareTo("吖") < 0)
                {
                    return cn;
                }
                else if ((cn.CompareTo("吖") >= 0) && cn.CompareTo("八") < 0)
                {
                    return "A";
                }

                else if ((cn.CompareTo("八") >= 0) && cn.CompareTo("嚓") < 0)
                {
                    return "B";
                }

                else if ((cn.CompareTo("嚓") >= 0) && cn.CompareTo("咑") < 0)
                {
                    return "C";
                }
                else if ((cn.CompareTo("咑") >= 0) && cn.CompareTo("妸") < 0)
                {
                    return "D";
                }
                else if ((cn.CompareTo("妸") >= 0) && cn.CompareTo("发") < 0)
                {
                    return "E";
                }
                else if ((cn.CompareTo("发") >= 0) && cn.CompareTo("旮") < 0)
                {
                    return "F";
                }
                else if ((cn.CompareTo("旮") >= 0) && cn.CompareTo("铪") < 0)
                {
                    return "G";
                }
                else if ((cn.CompareTo("铪") >= 0) && cn.CompareTo("讥") < 0)
                {
                    return "H";
                }
                else if ((cn.CompareTo("讥") >= 0) && cn.CompareTo("咔") < 0)
                {
                    return "J";
                }
                else if ((cn.CompareTo("咔") >= 0) && cn.CompareTo("垃") < 0)
                {
                    return "K";
                }
                else if ((cn.CompareTo("垃") >= 0) && cn.CompareTo("嘸") < 0)
                {
                    return "L";
                }
                else if ((cn.CompareTo("嘸") >= 0) && cn.CompareTo("拏") < 0)
                {
                    return "M";
                }
                else if ((cn.CompareTo("拏") >= 0) && cn.CompareTo("噢") < 0)
                {
                    return "N";
                }
                else if ((cn.CompareTo("噢") >= 0) && cn.CompareTo("妑") < 0)
                {
                    return "O";
                }
                else if ((cn.CompareTo("妑") >= 0) && cn.CompareTo("七") < 0)
                {
                    return "P";
                }
                else if ((cn.CompareTo("七") >= 0) && cn.CompareTo("亽") < 0)
                {
                    return "Q";
                }
                else if ((cn.CompareTo("亽") >= 0) && cn.CompareTo("仨") < 0)
                {
                    return "R";
                }
                else if ((cn.CompareTo("仨") >= 0) && cn.CompareTo("他") < 0)
                {
                    return "S";
                }
                else if ((cn.CompareTo("他") >= 0) && cn.CompareTo("哇") < 0)
                {
                    return "T";
                }
                else if ((cn.CompareTo("哇") >= 0) && cn.CompareTo("夕") < 0)
                {
                    return "W";
                }
                else if ((cn.CompareTo("夕") >= 0) && cn.CompareTo("丫") < 0)
                {
                    return "X";
                }
                else if ((cn.CompareTo("丫") >= 0) && cn.CompareTo("帀") < 0)
                {
                    return "Y";
                }
                else if ((cn.CompareTo("帀") >= 0) && cn.CompareTo("咗") < 0)
                {
                    return "Z";
                }

                return cn;
            }
            else return cn;

        }