VC UrlEncode(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);

}
本文为“技术点滴”的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

发表回复

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