VC 实现 Url 编码

VC 实现 Url 编码:(unicode版本)

CString UrlEncode(CString strUnicode )
{
        LPCWSTR unicode = T2CW( strUnicode);
        int len = WideCharToMultiByte( CP_UTF8, 0, unicode, -1, 0, 0, 0, 0);
        if (!len)
               return strUnicode;
        char *utf8 = new char[len + 1];
        char *utf8temp = utf8;
       WideCharToMultiByte( CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0);
       utf8[len] = NULL;
        CString strTemp, strEncodeData;
        while (*utf8 != '\0')
       {
              strTemp.Format( _T( "%%%2x"), (BYTE )*utf8);
              strEncodeData += strTemp;
              ++utf8;
       }

        delete[]utf8temp;

        return CString(strEncodeData);

}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注