我现在有要查全国的分店如有下以
省 txt_Province
市 txt_City
比如我在txt_Province输入 g 在 txt_City 输入 z
就会查找到所有在我 CityList表里面 省份中的汉字的第一个拼音为g的
和城市中的第一个字母为z的城市如
广东   广州   省g 在"广东"里有 z在"广州""堪江" 里面有就会查找到这相关的
广西   柳州   也是有g和z的
这个要怎么来查谢谢

解决方案 »

  1.   

    #region 汉字相关操作
            ///   <summary>   
            ///   获取一串汉字的拼音声母   
            ///   </summary>   
            ///   <param   name="chinese">Unicode格式的汉字字符串</param>   
            ///   <returns>拼音声母字符串</returns>   
            ///   <example>   
            ///   “新桥软件”转换为“xqrj”   
            ///   </example>   
            public static String ConvertToChn(String chinese)
            {
                char[] buffer = new char[chinese.Length];
                for (int i = 0; i < chinese.Length; i++)
                {
                    buffer[i] = ConvertCHN(chinese[i]);
                }
                return new String(buffer);
            }        ///   <summary>   
            ///   获取一个汉字的拼音声母   
            ///   </summary>   
            ///   <param   name="chinese">Unicode格式的一个汉字</param>   
            ///   <returns>汉字的声母</returns>   
            public static char ConvertCHN(Char chinese)
            {
                Encoding gb2312 = Encoding.GetEncoding("GB2312");
                Encoding unicode = Encoding.Unicode;            //   Convert   the   string   into   a   byte[].   
                byte[] unicodeBytes = unicode.GetBytes(new Char[] { chinese });
                //   Perform   the   conversion   from   one   encoding   to   the   other.   
                byte[] asciiBytes = Encoding.Convert(unicode, gb2312, unicodeBytes);            //   计算该汉字的GB-2312编码   
                int n = (int)asciiBytes[0] << 8;
                n += (int)asciiBytes[1];            //   根据汉字区域码获取拼音声母   
                if (In(0xB0A1, 0xB0C4, n)) return 'a';
                if (In(0XB0C5, 0XB2C0, n)) return 'b';
                if (In(0xB2C1, 0xB4ED, n)) return 'c';
                if (In(0xB4EE, 0xB6E9, n)) return 'd';
                if (In(0xB6EA, 0xB7A1, n)) return 'e';
                if (In(0xB7A2, 0xB8c0, n)) return 'f';
                if (In(0xB8C1, 0xB9FD, n)) return 'g';
                if (In(0xB9FE, 0xBBF6, n)) return 'h';
                if (In(0xBBF7, 0xBFA5, n)) return 'j';
                if (In(0xBFA6, 0xC0AB, n)) return 'k';
                if (In(0xC0AC, 0xC2E7, n)) return 'l';
                if (In(0xC2E8, 0xC4C2, n)) return 'm';
                if (In(0xC4C3, 0xC5B5, n)) return 'n';
                if (In(0xC5B6, 0xC5BD, n)) return 'o';
                if (In(0xC5BE, 0xC6D9, n)) return 'p';
                if (In(0xC6DA, 0xC8BA, n)) return 'q';
                if (In(0xC8BB, 0xC8F5, n)) return 'r';
                if (In(0xC8F6, 0xCBF0, n)) return 's';
                if (In(0xCBFA, 0xCDD9, n)) return 't';
                if (In(0xCDDA, 0xCEF3, n)) return 'w';
                if (In(0xCEF4, 0xD188, n)) return 'x';
                if (In(0xD1B9, 0xD4D0, n)) return 'y';
                if (In(0xD4D1, 0xD7F9, n)) return 'z';
                return '\0';
            }        private static bool In(int Lp, int Hp, int Value)
            {
                return ((Value <= Hp) && (Value >= Lp));
            }        //将汉字转成拼音字头的方法“中华人民共和国”-->"ZHRMGHG"             // 是采用对应的区位的方法,但有些汉字不在这个范围里,大家试一下           public string hz2py(string hz)     //获得汉字的区位码   
            {
                byte[] sarr = System.Text.Encoding.Default.GetBytes(hz);
                int len = sarr.Length;
                if (len > 1)
                {
                    byte[] array = new byte[2];
                    array = System.Text.Encoding.Default.GetBytes(hz);                int i1 = (short)(array[0] - '\0');
                    int i2 = (short)(array[1] - '\0');                //unicode解码方式下的汉字码   
                    //                         array   =   System.Text.Encoding.Unicode.GetBytes(hz);   
                    //                         int   i1   =   (short)(array[0]   -   '\0');   
                    //                         int   i2   =   (short)(array[1]   -   '\0');   
                    //                         int   t1   =   Convert.ToInt32(i1,16);   
                    //                         int   t2   =   Convert.ToInt32(i2,16);                   int tmp = i1 * 256 + i2;
                    string getpychar = "*";//找不到拼音码的用*补位                   if (tmp >= 45217 && tmp <= 45252) { getpychar = "A"; }
                    else if (tmp >= 45253 && tmp <= 45760) { getpychar = "B"; }
                    else if (tmp >= 47761 && tmp <= 46317) { getpychar = "C"; }
                    else if (tmp >= 46318 && tmp <= 46825) { getpychar = "D"; }
                    else if (tmp >= 46826 && tmp <= 47009) { getpychar = "E"; }
                    else if (tmp >= 47010 && tmp <= 47296) { getpychar = "F"; }
                    else if (tmp >= 47297 && tmp <= 47613) { getpychar = "G"; }
                    else if (tmp >= 47614 && tmp <= 48118) { getpychar = "H"; }
                    else if (tmp >= 48119 && tmp <= 49061) { getpychar = "J"; }
                    else if (tmp >= 49062 && tmp <= 49323) { getpychar = "K"; }
                    else if (tmp >= 49324 && tmp <= 49895) { getpychar = "L"; }
                    else if (tmp >= 49896 && tmp <= 50370) { getpychar = "M"; }
                    else if (tmp >= 50371 && tmp <= 50613) { getpychar = "N"; }
                    else if (tmp >= 50614 && tmp <= 50621) { getpychar = "O"; }
                    else if (tmp >= 50622 && tmp <= 50905) { getpychar = "P"; }
                    else if (tmp >= 50906 && tmp <= 51386) { getpychar = "Q"; }
                    else if (tmp >= 51387 && tmp <= 51445) { getpychar = "R"; }
                    else if (tmp >= 51446 && tmp <= 52217) { getpychar = "S"; }
                    else if (tmp >= 52218 && tmp <= 52697) { getpychar = "T"; }
                    else if (tmp >= 52698 && tmp <= 52979) { getpychar = "W"; }
                    else if (tmp >= 52980 && tmp <= 53640) { getpychar = "X"; }
                    else if (tmp >= 53689 && tmp <= 54480) { getpychar = "Y"; }
                    else if (tmp >= 54481 && tmp <= 55289) { getpychar = "Z"; }
                    return getpychar;
                }
                else
                {
                    return hz;
                }
            }        public string transpy(string strhz)     //把汉字字符串转换成拼音码   
            {
                string strtemp = "";
                int strlen = strhz.Length;
                for (int i = 0; i <= strlen - 1; i++)
                {
                    strtemp += hz2py(strhz.Substring(i, 1));
                }
                return strtemp;
            }   
            #endregion
      

  2.   

    /// </summary〉 
    /// <param name="str"〉要转换的汉字字符串</param〉 
    /// <returns〉拼音缩写</returns〉 
    public string GetPYString(string str) 
    {    string tempStr = "";   foreach(char c in str)    {    if((int)c >= 33 && (int)c <=126)    {//字母和符号原样保留    tempStr += c.ToString();   }    else    {//累加拼音声母    tempStr += GetPYChar(c.ToString());   }    }    return tempStr;
    } /// <summary〉 
    /// /// Code By [email protected] 
    /// 2004-11-30 
    /// </summary〉 
    /// <param name="c"〉要转换的单个汉字</param〉 
    /// <returns〉拼音声母</returns〉 
    public string GetPYChar(string c) 
    {    byte[] array = new byte[2];   array = System.Text.Encoding.Default.GetBytes(c);   int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));
       if ( i < 0xB0A1) return "*";   if ( i < 0xB0C5) return "a";   if ( i < 0xB2C1) return "b";   if ( i < 0xB4EE) return "c";   if ( i < 0xB6EA) return "d";   if ( i < 0xB7A2) return "e";   if ( i < 0xB8C1) return "f";   if ( i < 0xB9FE) return "g";   if ( i < 0xBBF7) return "h";   if ( i < 0xBFA6) return "g";   if ( i < 0xC0AC) return "k";   if ( i < 0xC2E8) return "l";   if ( i < 0xC4C3) return "m";   if ( i < 0xC5B6) return "n";   if ( i < 0xC5BE) return "o";   if ( i < 0xC6DA) return "p";   if ( i < 0xC8BB) return "q";   if ( i < 0xC8F6) return "r";   if ( i < 0xCBFA) return "s";   if ( i < 0xCDDA) return "t";   if ( i < 0xCEF4) return "w";   if ( i < 0xD1B9) return "x";   if ( i < 0xD4D1) return "y";   if ( i < 0xD7FA) return "z";
       return "*";
    }
      

  3.   

    数据库中取汉字拼音
    http://sdlyi.bokee.com/2701149.html
    http://www.blog.ztlz.net/user1/1/archives/2005/1409.shtml