把字典上每个字母开头的字都找出来,然后要查索引的字和这些字比较。
加入字典上t开头的第一个字是“他"(仅是假设),s开头的第一个字是“斯”,那么如果目标字在“斯”和“他”之间,则目标字对应的索引为s,其实也就是根据区间来找索引。目前我也只能想到这个方法,如果是多音字……大家再讨论吧

解决方案 »

  1.   

    没有什么函数直接支持嘛?windows的文件夹是怎么排序的?
      

  2.   

    “斯”>“他”本来就是先转化为S  , T.然后再排序的吧?
      

  3.   

    如果楼主想得到的是一个汉字的拼音编码可以用这个函数,字符串的话循环调用就可以,这个只能得到拼音的首字母,对于生僻字可能还不准,还有一种方法是在外部使用字典编码文件了,但是效率会降低,不过能获得拼音完整编码,并且很精确。private 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>=45761&&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<=53688){getpychar= "X";}
    else if(tmp>=53689&&tmp<=54480){getpychar= "Y";}
    else if(tmp>=54481&&tmp<=55289){getpychar= "Z";}
    return getpychar;
    }
    else
    {
    return hz;
    }
    }
      

  4.   

    好代码,谢谢!unicode编码要用下面这段嘛?我就用原来的也没问题啊?C#下的中文本来是不是unicode的?//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);
      

  5.   

    unicode解码方式下的汉字码是怎么回事我也不知道,可能这么写是说明对不同的编码方式需要不同的处理吧。
    这是使用了好久的函数了,具体细节也记不清了