【救急】邮件内码转换问题 各位大侠,各位看官: 1、请问在邮件中的gb2312的编码格式如何能够在繁体中显示? 2、utf-8的编码格式能够从根据不同的系统进行自动的正确显示。 3、unicode是否在简繁体系统中正常显示呢?如何转码问题?问题多多?希望大家给点建议!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 通用的做法是都用unicode。 首先系统中要相应的字体。试试SetThreadLocale。Unicode是可以正常显示的,转码时只要给对codepage即可。 int s2u(const char* pSrc, BYTE* pDst, int nSrcLength){ int nDstLen = 0; int nOffset = nSrcLength; int nTotal = 0; WCHAR wchr[ 4096 ]; try { while( nOffset>0 ) { nDstLen = ::MultiByteToWideChar(CP_ACP, 0, pSrc, nOffset, wchr, 4096);////////////////////我没做过纯unicode的程序,只是听大家说unicode版本的程序到哪里都一样。前面的代码是ascii转unicode的。 你这里说的unicode应该是指UCS2编码方式而utf-8也是一种编码方式,他们都是对unicode字符集进行编码,该字符集是世界兼容的。1、请问在邮件中的gb2312的编码格式如何能够在繁体中显示? cp936先转cp950再显示可以参考如下函数: //--------------------------------------------------------------------------- // GBK转大五码 void __fastcall GBK2BIG5(char *szBuf) { if(!strcmp(szBuf, "")) return ; int nStrLen = strlen(szBuf); wchar_t *pws = new wchar_t[nStrLen + 1]; try { MultiByteToWideChar(936, 0, szBuf, nStrLen, pws, nStrLen + 1); BOOL bValue = false; WideCharToMultiByte(950, 0, pws, nStrLen, szBuf, nStrLen + 1, "?", &bValue); szBuf[nStrLen] = 0; } __finally { delete[] pws; } } 謝謝你,1、请问在邮件中的gb2312的编码格式如何能够在繁体中显示?cp936先转cp950再显示你這個回答我還不是很明白能否說得清楚些呢? 额,哪里不是很清楚呢?GBK2BIG5这个函数或许你调用1下先看看比较好。简体和繁体系统使用不同的字符集所以需要先转换编码。然而没有直接这么转换的API, 但多字节转宽字符API MultiByteToWideChar和 宽字符转多字节API WideCharToMultiByte是可以指定多字节部分的代码页的,所以产生GBK2BIG5这个函数的写法 unicode可以满足要求,但是编程处理过程中一定小心,不然会丢失数据~就是全用宽字符集处理咯~ 你這邊可能理解錯了,我的意思是說,如何我想在繁體系統中顯示簡體字的話我要如何處理呢?而不是gb2312轉gbk在轉big5的過程。 你说的是GB2312编码,繁体转换为简体?LCMapString(0x0804,LCMAP_SIMPLIFIED_CHINESE, 繁体文字, -1, 简体文字, iLen); 现在是遇到这样的事情,邮件含有简体字在简体系统中发到放到繁体系统中的时候,我先是使用gbk转为utf8,然后再使用utf8转为big5,结果发现很多字是无法显示的。如果我想简体字能够在繁体系统中正常显示的话,我应该要转为什么编码呢??? 被你刚发来的死信弄晕了。看来还是内码转换问题,我建议发送端文字转为unicode或是utf8,在阅读端直接用该编码查看。 目前在繁体系统的outlook中在接收邮件的时候我们也会看到在主题中部分字是无法显示的,但是为什么他的内容还是能够显示正常呢? 我转为utf-8码值后,存入数据库后,再从数据库中取出来,结果看到无法认识的乱码。 从utf8转到其它内码, 中间先转为unicode,再转向其它内码. 我在debug的时候在就已经看到的是乱码,问题好玄???真不知道别人是怎么在繁体中显示简体的!!! 关于utf8转asciichar *utf82ascii( unsigned char *utf8, unsigned short length, char *buf ){ int i = 0; unsigned short a; unsigned char b; char *p = buf; unsigned char t[ 2 ]; do { if( 0xe0 == ( *utf8 & 0xf0 ) && 0x80 == ( *( utf8 + 1 ) & 0xc0 ) && 0x80 == ( *( utf8 + 2 ) & 0xc0 ) ) { //3个字节 b = *utf8; b &= 0x0f; a = b; a <<= 6; b = *( utf8 + 1 ); b &= 0x3f; a |= b; a <<= 6; b = *( utf8 + 2 ); b &= 0x3f; a |= b; t[ 0 ] = ( a >> 8 ) & 0xff; t[ 1 ] = ( a & 0xff ); u2s( t, 2, p ); p += 2; i += 3; utf8 += 3; } else if ( 0xc0 == ( *utf8 & 0xe0 ) && 0x80 == ( *( utf8 + 1 ) & 0xc0 ) ) { //2个字节 b = *utf8; b &= 0x1f; a = b; a <<= 6; b = *( utf8 + 1 ); b &= 0x3f; a |= b; t[ 0 ] = ( a >> 8 ) & 0xff; t[ 1 ] = ( a & 0xff ); u2s( t, 2, p ); p += 2; i += 2; utf8 += 2; } else { //1个字节 *( p++ ) = *( utf8++ ); i++; } } while ( i < length ); *p = 0; return buf;} 里面涉及了一个u2s函数,将ucs2的流转成ascii的。char *u2s( unsigned char *buf, unsigned short length, char *tmpbuf ){ int i; char *p; char s[ 16 ] = ""; wchar_t wstr[ 1 ]; CString mstr; int l, curlen; *tmpbuf = 0; curlen = 0; mstr = _T( "" ); for( i = 0; i < ( int )length; i += 2 ) { p = ( char * )wstr; *p = *( buf + 1 ); //high *( p + 1 ) = *buf; //low mstr = wstr; memset( s, 0, sizeof( s ) ); strcat( s, ( const char * )mstr ); if( *buf ) //if low is not 0 { s[ 2 ] = 0; l = 2; } else { s[ 1 ] = 0; l = 1; } strcat( tmpbuf + curlen, ( const char * )s ); curlen += l; buf += 2; } return tmpbuf;} 两种多字节字符串相互转换需要先转成Unicode,再从Unicode转成目标字符集。 如何在对话框启动后,自动启动定时器. MFC窗口句柄问题 mfc为何要注册DefWindowProc然后又改为用AfxWndProc()分发消息? 怎样将CString字符串变量转换成宽字符? 线程debug问题? 我的vc路,一个郁闷人的烦恼....... 关于windows下的换行符 怎么在公司内跨网段发网络唤醒包呢? 大家看我费劲从.dll中导出.tlh文件中的内容!! 这能用吗? VS2010CMFToolBar工具栏靠顶靠右摆放 请问一个数据集的问题 com编程出现问题。。。客户端调用CreateInstance时出错 。。。。请帮忙 解决给200分 不够再加
试试SetThreadLocale。
Unicode是可以正常显示的,转码时只要给对codepage即可。
{
int nDstLen = 0;
int nOffset = nSrcLength;
int nTotal = 0;
WCHAR wchr[ 4096 ];
try
{
while( nOffset>0 )
{
nDstLen = ::MultiByteToWideChar(CP_ACP, 0, pSrc, nOffset, wchr, 4096);////////////////////
我没做过纯unicode的程序,只是听大家说unicode版本的程序到哪里都一样。前面的代码是ascii转unicode的。
而utf-8也是一种编码方式,他们都是对unicode字符集进行编码,该字符集是世界兼容的。1、请问在邮件中的gb2312的编码格式如何能够在繁体中显示?
cp936先转cp950再显示可以参考如下函数: //---------------------------------------------------------------------------
// GBK转大五码
void __fastcall GBK2BIG5(char *szBuf)
{
if(!strcmp(szBuf, ""))
return ;
int nStrLen = strlen(szBuf);
wchar_t *pws = new wchar_t[nStrLen + 1];
try
{
MultiByteToWideChar(936, 0, szBuf, nStrLen, pws, nStrLen + 1);
BOOL bValue = false;
WideCharToMultiByte(950, 0, pws, nStrLen, szBuf, nStrLen + 1, "?", &bValue);
szBuf[nStrLen] = 0;
}
__finally
{
delete[] pws;
}
}
cp936先转cp950再显示
你這個回答我還不是很明白能否說得清楚些呢?
GBK2BIG5这个函数或许你调用1下先看看比较好。
简体和繁体系统使用不同的字符集所以需要先转换编码。然而没有直接这么转换的API,
但多字节转宽字符API MultiByteToWideChar和
宽字符转多字节API WideCharToMultiByte是可以指定多字节部分的代码页的,所以产生GBK2BIG5这个函数的写法
但是编程处理过程中一定小心,
不然会丢失数据~
就是全用宽字符集处理咯~
看来还是内码转换问题,我建议发送端文字转为unicode或是utf8,在阅读端直接用该编码查看。
utf82ascii( unsigned char *utf8, unsigned short length, char *buf )
{
int i = 0;
unsigned short a;
unsigned char b;
char *p = buf;
unsigned char t[ 2 ];
do
{
if( 0xe0 == ( *utf8 & 0xf0 ) &&
0x80 == ( *( utf8 + 1 ) & 0xc0 ) &&
0x80 == ( *( utf8 + 2 ) & 0xc0 ) )
{
//3个字节
b = *utf8;
b &= 0x0f;
a = b; a <<= 6;
b = *( utf8 + 1 );
b &= 0x3f;
a |= b; a <<= 6;
b = *( utf8 + 2 );
b &= 0x3f;
a |= b; t[ 0 ] = ( a >> 8 ) & 0xff;
t[ 1 ] = ( a & 0xff );
u2s( t, 2, p ); p += 2; i += 3;
utf8 += 3;
}
else if ( 0xc0 == ( *utf8 & 0xe0 ) &&
0x80 == ( *( utf8 + 1 ) & 0xc0 ) )
{
//2个字节
b = *utf8;
b &= 0x1f;
a = b; a <<= 6;
b = *( utf8 + 1 );
b &= 0x3f;
a |= b; t[ 0 ] = ( a >> 8 ) & 0xff;
t[ 1 ] = ( a & 0xff );
u2s( t, 2, p ); p += 2; i += 2;
utf8 += 2;
}
else
{
//1个字节
*( p++ ) = *( utf8++ );
i++;
}
} while ( i < length );
*p = 0;
return buf;
}
u2s( unsigned char *buf, unsigned short length, char *tmpbuf )
{
int i;
char *p;
char s[ 16 ] = "";
wchar_t wstr[ 1 ];
CString mstr;
int l, curlen; *tmpbuf = 0;
curlen = 0;
mstr = _T( "" ); for( i = 0; i < ( int )length; i += 2 )
{
p = ( char * )wstr;
*p = *( buf + 1 ); //high
*( p + 1 ) = *buf; //low
mstr = wstr;
memset( s, 0, sizeof( s ) );
strcat( s, ( const char * )mstr );
if( *buf ) //if low is not 0
{
s[ 2 ] = 0;
l = 2;
}
else
{
s[ 1 ] = 0;
l = 1;
}
strcat( tmpbuf + curlen, ( const char * )s );
curlen += l; buf += 2;
} return tmpbuf;
}