c++ web服务器转换浏览器提交的汉字



 

 

#include <stdio.h>

#include <stdlib.h>

#include <iostream>

#include <Windows.h>

using namespace std;

int main()

{

         chars[] = "%E4%B8%AD%E5%9B%BD%E9%93%B6%E8%A1%8C%E6%AD%A6%E6%B1%89%E5%B8%82%E9%87%91%E8%9E%8D%E6%B8%AF%E9%93%B6%E8%A1%8C";

         intlen = strlen(s);

         char*temps = new char[len+1];

         temps[len]= '\0';

         inttemps_pos = 0;

         //去掉%

         for(int i = 0;i<len;++i)

         {

                   if(s[i] != '%')

                   {

                            temps[temps_pos]= s[i];

                            temps_pos++;

                   }

         }

         temps[temps_pos]= '\0';

         cout<<temps<<endl;

         inttemps_len = strlen(temps);

         intUTF8len = temps_len/2;

         char*UTF8str = new char[UTF8len+1];

 

         UTF8str[UTF8len]= '\0';

         //把字符转换成数字,得到真实的UTF8

         for(int i = 0;i<UTF8len*2;)

         {

                   charconvert[3] = {0};

                   convert[0]= temps[i++];

                   convert[1]= temps[i++];

                   char*end;

                   inttempint = strtol(convert,&end,16);

                   UTF8str[i/2-1]= tempint;

         }

 

         //UTF8转换到UTF16

         intwcslen = ::MultiByteToWideChar(CP_UTF8,NULL,UTF8str,UTF8len,NULL,0);

         wchar_t*wszString = new wchar_t[wcslen + 1];

         ::MultiByteToWideChar(CP_UTF8,NULL,UTF8str,UTF8len,wszString,wcslen);

         wszString[wcslen]= L'\0';

         //设置区域

         std::wcout.imbue(std::locale("CHS"));

         wcout<<wszString<<endl;

         delete[]temps;

         delete[]UTF8str;

         delete[]wszString;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值