请问谁用C#写过DLL,实现计算20902个汉字的拼音首字母?十分感谢,急问!!

解决方案 »

  1.   

    这是用vb写的,自己转换一下吧,^_^
    '获取汉字拼音第一字母
    function getpychar(char) 
        dim tmp
        tmp=65536+asc(char) 
        if(tmp>=45217 and tmp<=45252) then  
        getpychar= "A" 
        elseif(tmp>=45253 and tmp<=45760) then 
        getpychar= "B" 
        elseif(tmp>=45761 and tmp<=46317) then 
        getpychar= "C" 
        elseif(tmp>=46318 and tmp<=46825) then 
        getpychar= "D" 
        elseif(tmp>=46826 and tmp<=47009) then  
        getpychar= "E" 
        elseif(tmp>=47010 and tmp<=47296) then  
        getpychar= "F" 
        elseif(tmp>=47297 and tmp<=47613) then  
        getpychar= "G" 
        elseif(tmp>=47614 and tmp<=48118) then 
        getpychar= "H" 
        elseif(tmp>=48119 and tmp<=49061) then 
        getpychar= "J" 
        elseif(tmp>=49062 and tmp<=49323) then  
        getpychar= "K" 
        elseif(tmp>=49324 and tmp<=49895) then  
        getpychar= "L" 
        elseif(tmp>=49896 and tmp<=50370) then  
        getpychar= "M" 
        elseif(tmp>=50371 and tmp<=50613) then  
        getpychar= "N" 
        elseif(tmp>=50614 and tmp<=50621) then  
        getpychar= "O" 
        elseif(tmp>=50622 and tmp<=50905) then 
        getpychar= "P" 
        elseif(tmp>=50906 and tmp<=51386) then  
        getpychar= "Q" 
        elseif(tmp>=51387 and tmp<=51445) then  
        getpychar= "R" 
        elseif(tmp>=51446 and tmp<=52217) then  
        getpychar= "S" 
        elseif(tmp>=52218 and tmp<=52697) then  
        getpychar= "T" 
        elseif(tmp>=52698 and tmp<=52979) then  
        getpychar= "W" 
        elseif(tmp>=52980 and tmp<=53688) then  
        getpychar= "X" 
        elseif(tmp>=53689 and tmp<=54480) then  
        getpychar= "Y" 
        elseif(tmp>=54481 and tmp<=62289) then 
        getpychar= "Z" 
        else '如果不是中文,则不处理 
        getpychar=char 
        end if 
    end function
      

  2.   

    我的意思是将一串汉字转换成声母得字符串,就是首字母的字符串.这个是实现这个功能吗?
    我不会VB.你会C#吗?十分谢谢! :)
      

  3.   

    static public string GetChineseSpell(string strText)
    {
    int len = strText.Length;
    string myStr = "";
    for(int i=0;i<len;i++)
    {
    myStr += getSpell(strText.Substring(i,1));
    }
    return myStr;
    }
    static public string getSpell(string cnChar)
    {
    byte[] arrCN = Encoding.Default.GetBytes(cnChar);
    if(arrCN.Length > 1)
    {
    int area = (short)arrCN[0];
    int pos = (short)arrCN[1];
    int code = (area<<8) + pos;
    int[] areacode = {45217,45253,45761,46318,46826,47010,47297,47614,48119,48119,49062,49324,49896,50371,50614,50622,50906,51387,51446,52218,52698,52698,52698,52980,53689,54481};
    for(int i=0;i<26;i++)
    {
    int max = 55290;
    if(i != 25) max = areacode[i+1];
    if(areacode[i]<=code && code<max)
    {
    return Encoding.Default.GetString(new byte[]{(byte)(65+i)});
    }
    }
    return "*";
    }
    else return cnChar;
    }
      

  4.   

    我这有一个DLL文件,可以得到一个或几个汉字的全拼及简拼。如果你是学习可以自己好好研究一下,如果是公司做开发的,不如直接用别人已经开发的东西。很好用的。我所使用的组件的名称:ChineseToPy。楼主可以到网上找一下。
      

  5.   

    http://jhtchina.cnblogs.com/articles/328428.html
      

  6.   

    /// <summary>
    /// 获取一串汉字的拼音声母
    /// </summary>
    /// <param name="chinese">Unicode格式的汉字字符串</param>
    /// <returns>拼音声母字符串</returns>
    public static String Convert(String chinese)
    {
    char[] buffer = new char[chinese.Length];
    for(int i=0; i<chinese.Length; i++)
    {
    buffer[i] = Convert(chinese[i]);
    }
    return new String(buffer);
    } /// <summary>
    /// 获取一个汉字的拼音声母
    /// </summary>
    /// <param name="chinese">Unicode格式的一个汉字</param>
    /// <returns>汉字的声母</returns>
    public static char Convert(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));
    }