• [转]vc 汉字汉语拼音首字母如何获取


    //源码:在vc中实现获取汉字拼音的首字母

    Author: lixiaosan
    Date: 05/26/2006
    /********************************************************************************************
    /* Syntax
    /*        GetFirstLetter(CString strName, CString& strFirstLetter)
    /* Remarks:
    /*        Get the first letter of pinyin according to specified Chinese character.
    /* Parameters:
    /*        strName            - a CString object that is to be parsed.
    /*        strFirstLetter     - a CString object that is to receive the string of the first letter.
    /* Return Values:
    /*        None.
    /* Author:
    /*        lixiaosan
    /* Create Date:
    /*        05-26-2006
    /********************************************************************************************
    void GetFirstLetter(CString strName, CString& strFirstLetter)
    {
        TBYTE ucHigh, ucLow;
        int nCode;
        CString strRet;

        strFirstLetter.Empty();

        for (int i=0; i<strName.GetLength(); i++)
        {
            if ( (TBYTE)strName[i] < 0x80 )
                continue;

            ucHigh = (TBYTE)strName[i];
            ucLow = (TBYTE)strName[i+1];
            if ( ucHigh < 0xa1 || ucLow < 0xa1)
                continue;
            else
                // Treat code by section-position as an int type parameter,
                // so make following change to nCode.
                nCode = (ucHigh - 0xa0) * 100 + ucLow - 0xa0;

            FirstLetter(nCode, strRet);
            strFirstLetter += strRet;
            i++;
        }
    }

    /********************************************************************************************
    /* Syntax
    /*        void FirstLetter(int nCode, CString& strLetter)
    /* Remarks:
    /*        Get the first letter of pinyin according to specified Chinese character code.
    /* Parameters:
    /*        nCode         - the code of the chinese character.
    /*        strLetter      - a CString object that is to receive the string of the first letter.
    /* Return Values:
    /*        None.
    /* Author:
    /*        lixiaosan
    /* Create Date:
    /*        05-26-2006
    /********************************************************************************************
    void FirstLetter(int nCode, CString& strLetter)
    {
       if(nCode >= 1601 && nCode < 1637) strLetter = _T("A");
       if(nCode >= 1637 && nCode < 1833) strLetter = _T("B");
       if(nCode >= 1833 && nCode < 2078) strLetter = _T("C");
       if(nCode >= 2078 && nCode < 2274) strLetter = _T("D");
       if(nCode >= 2274 && nCode < 2302) strLetter = _T("E");
       if(nCode >= 2302 && nCode < 2433) strLetter = _T("F");
       if(nCode >= 2433 && nCode < 2594) strLetter = _T("G");
       if(nCode >= 2594 && nCode < 2787) strLetter = _T("H");
       if(nCode >= 2787 && nCode < 3106) strLetter = _T("J");
       if(nCode >= 3106 && nCode < 3212) strLetter = _T("K");
       if(nCode >= 3212 && nCode < 3472) strLetter = _T("L");
       if(nCode >= 3472 && nCode < 3635) strLetter = _T("M");
       if(nCode >= 3635 && nCode < 3722) strLetter = _T("N");
       if(nCode >= 3722 && nCode < 3730) strLetter = _T("O");
       if(nCode >= 3730 && nCode < 3858) strLetter = _T("P");
       if(nCode >= 3858 && nCode < 4027) strLetter = _T("Q");
       if(nCode >= 4027 && nCode < 4086) strLetter = _T("R");
       if(nCode >= 4086 && nCode < 4390) strLetter = _T("S");
       if(nCode >= 4390 && nCode < 4558) strLetter = _T("T");
       if(nCode >= 4558 && nCode < 4684) strLetter = _T("W");
       if(nCode >= 4684 && nCode < 4925) strLetter = _T("X");
       if(nCode >= 4925 && nCode < 5249) strLetter = _T("Y");
       if(nCode >= 5249 && nCode < 5590) strLetter = _T("Z");
    }


    How to use:

        CString strName, strRes;
        strName = _T("A李小三");
        GetFirstLetter(strName, strRes);
        //Then the value of strRes is "LXS".

  • 相关阅读:
    百度地图V1.5 LocalSearch增加浮动窗体的操作内容
    百度地图LV1.5实践项目开发工具类bmap.util.jsV1.1
    Jquery时间快捷控件(Jtime)配置v1.1
    百度地图LV1.5实践项目开发工具类bmap.util.jsV1.0
    Jquery时间快捷控件(Jtime)配置v1.0
    百度地图JavaScript API V1.5初级开发工具类
    Cocos2d-x可以实现的动画效果
    禁掉Apache web server签名 How to turn off server signature on Apache web server
    codevs 3372 选学霸(hash+并查集+多重背包)
    从头认识Spring-3.4 简单的AOP日志实现-扩展添加检查订单功能,以便记录并检測输入的參数
  • 原文地址:https://www.cnblogs.com/vic_lu/p/2434988.html
Copyright © 2020-2023  润新知