求救:URL中的"%E4%BB%80%E4%B9%88"编码,如何转换为中文?

时间:2023-01-26 10:30:42
从以下URL中取出的中文编码,请问如何转换为中文?

http://auto.search.msn.com/response.asp?MT=%E4%BB%80%E4%B9%88&srch=5&prov=&utf8

MultiByteToWideChar用过但没成功,请问大家有办法吗?

12 个解决方案

#1


代码页用CP_UTF8?

UTF8 is a code page that uses a string of bytes to represent a 16-bit Unicode string where ASCII text (<=U+007F) remains unchanged as a single byte, U+0080-07FF (including Latin, Greek, Cyrillic, Hebrew, and Arabic) is converted to a 2-byte sequence, and U+0800-FFFF (Chinese, Japanese, Korean, and others) becomes a 3-byte sequence. 

The advantage is that most ASCII text remains unchanged and almost all editors can read it. 

Windows NT4.0 supports Unicode<->UTF8 translation via MultiByteToWideChar()/WideCharToMultiByte(), using CP_UTF8 for the CodePage parameter, but it only works when none of the flags are set for dwFlags (therefore, you need to specify 0 for dwFlags). 

Also, UTF8 is not a valid encoding for command line arguments for Windows NT 4.0 or 5.0, and it is not supported on Windows 95.

#2


能给个具体的方法吗?

#3


做WEB的时候搞过中文乱码的处理
至于编码转换,不会!
看楼下的!

#4


做WEB的时候搞过中文乱码的处理
至于编码转换,不会!
看楼下的!

#5


做WEB的时候搞过中文乱码的处理
至于编码转换,不会!
看楼下的!

#6


把gbk汉字的两个字节对应的两个数字用16进制表示,然后前面加一个%,如汉字“媒”对应的两个字节就分别是c3,bd
给你编码解码函数:
/// URL encoding
string URLEncode(const string& input)
{
string text;
for(unsigned int i=0;i<input.length();i++)
{
if(input[i] == 0x20)
{
text += "+";
continue;
}

if(input[i]*0x80)
{
int c1 = (unsigned char)input[i];
text += "%" + DecimalToHexstr(c1);
i++;
int c2 = (unsigned char)input[i];
text += "%" + DecimalToHexstr(c2);
continue;
}

if(ispunct(input[i]))
{
text += "%";
text += input[i];
continue;
}

text += input[i];
}

return text;
}

/// URL decoding
string URLDecode(const string& input)
{
// decoding
string text;
for(unsigned int i=0;i<input.length();)
{
if(input[i]=='+')
{
text += " ";
i++;
continue;
}

if(input[i]!='%') //if inserted some ASCII characters
{
text += input[i];
i++;
continue;
}

/* convert hex to decimal, then to ASCII char.*/
string  sHex = "";
sHex += input[i+1];
sHex += input[i+2];
sHex = "0x" + sHex;
text += (char)strtol(sHex.c_str(),NULL,16);

i +=3;
}

return text;
}

#7


jixingzhong(瞌睡虫:选择了远方,只顾风雨兼程!):

DecimalToHexstr(c1);这个方法在哪里呀?

#8


jixingzhong(瞌睡虫:选择了远方,只顾风雨兼程!):

你给的方法不行呀!

#9


怎么没人会吗?

#10


up

#11


look in SHLWAPI.DLL and the UrlEscape and UrlUnescape... functions

#12


mark

#1


代码页用CP_UTF8?

UTF8 is a code page that uses a string of bytes to represent a 16-bit Unicode string where ASCII text (<=U+007F) remains unchanged as a single byte, U+0080-07FF (including Latin, Greek, Cyrillic, Hebrew, and Arabic) is converted to a 2-byte sequence, and U+0800-FFFF (Chinese, Japanese, Korean, and others) becomes a 3-byte sequence. 

The advantage is that most ASCII text remains unchanged and almost all editors can read it. 

Windows NT4.0 supports Unicode<->UTF8 translation via MultiByteToWideChar()/WideCharToMultiByte(), using CP_UTF8 for the CodePage parameter, but it only works when none of the flags are set for dwFlags (therefore, you need to specify 0 for dwFlags). 

Also, UTF8 is not a valid encoding for command line arguments for Windows NT 4.0 or 5.0, and it is not supported on Windows 95.

#2


能给个具体的方法吗?

#3


做WEB的时候搞过中文乱码的处理
至于编码转换,不会!
看楼下的!

#4


做WEB的时候搞过中文乱码的处理
至于编码转换,不会!
看楼下的!

#5


做WEB的时候搞过中文乱码的处理
至于编码转换,不会!
看楼下的!

#6


把gbk汉字的两个字节对应的两个数字用16进制表示,然后前面加一个%,如汉字“媒”对应的两个字节就分别是c3,bd
给你编码解码函数:
/// URL encoding
string URLEncode(const string& input)
{
string text;
for(unsigned int i=0;i<input.length();i++)
{
if(input[i] == 0x20)
{
text += "+";
continue;
}

if(input[i]*0x80)
{
int c1 = (unsigned char)input[i];
text += "%" + DecimalToHexstr(c1);
i++;
int c2 = (unsigned char)input[i];
text += "%" + DecimalToHexstr(c2);
continue;
}

if(ispunct(input[i]))
{
text += "%";
text += input[i];
continue;
}

text += input[i];
}

return text;
}

/// URL decoding
string URLDecode(const string& input)
{
// decoding
string text;
for(unsigned int i=0;i<input.length();)
{
if(input[i]=='+')
{
text += " ";
i++;
continue;
}

if(input[i]!='%') //if inserted some ASCII characters
{
text += input[i];
i++;
continue;
}

/* convert hex to decimal, then to ASCII char.*/
string  sHex = "";
sHex += input[i+1];
sHex += input[i+2];
sHex = "0x" + sHex;
text += (char)strtol(sHex.c_str(),NULL,16);

i +=3;
}

return text;
}

#7


jixingzhong(瞌睡虫:选择了远方,只顾风雨兼程!):

DecimalToHexstr(c1);这个方法在哪里呀?

#8


jixingzhong(瞌睡虫:选择了远方,只顾风雨兼程!):

你给的方法不行呀!

#9


怎么没人会吗?

#10


up

#11


look in SHLWAPI.DLL and the UrlEscape and UrlUnescape... functions

#12


mark