首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

UTF编码转换ANSI有关问题

2012-09-14 
【求助】UTF编码转换ANSI问题例如:汉字“大”的UTF编码是: %E5%A4%A7 ,现在想把UTF编码“%E5%A4%A7”转换为“大”

【求助】UTF编码转换ANSI问题
例如:汉字“大”的UTF编码是: %E5%A4%A7 ,现在想把UTF编码“%E5%A4%A7”转换为“大”字,通过调用MultiByteToWideChar()和WideCharToMultiByte()进行转换,UTF8ToANSI("%E5%A4%A7")执行后,编码仍为“%E5%A4%A7”,程序应该是把“%E5%A4%A7”当做英文字母进行处理了,请问在调用UTF8ToANSI("%E5%A4%A7")之前,还要对编码做什么处理?
(在网上通过在线编码工具进行转换,也没效果)

相关代码如下:
void UTF8ToANSI(char *input)
{
wchar_t *tmp=(wchar_t *)malloc(256);
UTF8ToUnicode(input,tmp);
UnicodeToANSI(tmp,input);
free(tmp);
}
void UTF8ToUnicode(char *input,wchar_t *output)
{
int textlen ;
textlen = MultiByteToWideChar( CP_UTF8, 0, input,-1, NULL,0 );  
memset(output,0,(textlen+1)*sizeof(wchar_t)); 
MultiByteToWideChar(CP_UTF8, 0,input,-1,(LPWSTR)output,textlen ); 
}
void UnicodeToANSI(wchar_t *input,char *output)
{
int textlen;
textlen = WideCharToMultiByte( CP_ACP, 0, input, -1, NULL, 0, NULL, NULL );
memset(output,0,textlen+1);
WideCharToMultiByte( CP_ACP, 0, input, -1, output, textlen, NULL, NULL );
}

[解决办法]
我承认我和你一起2了

你字符串怎么表示的, 是编码表示 应该这样

"\xE5\xA4\xA7"
[解决办法]

C/C++ code
char utfps[]="%E5%A4%A7";char utfs[4];int i,v;L=strlen(utfps);for (i=0;i<L/3;i++) {  sscanf(utfps+i*3+1,"%2X",&v);  utfs[i]=(char)(v&0xFFu);}utfs[i]=0;UTF8ToUnicode(utfs,... 

热点排行