C++简繁体转换

// #define LCMAP_SIMPLIFIED_CHINESE 0x02000000 // map traditional chinese to simplified chinese
// #define LCMAP_TRADITIONAL_CHINESE 0x04000000 // map simplified chinese to traditional chinese
char* TSTransform(const char* pStrSrc, int nToTS, char* pStrDst)
{
LCID lcid = MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC);
int nLength = LCMapStringA(lcid, nToTS, pStrSrc, -1, NULL, 0);
LCMapStringA(lcid, nToTS, pStrSrc, -1, pStrDst, nLength); // 繁体转简体
return pStrDst;
}

// 繁体中文转换成简体中文(基于GBK编码)
char* TraditionalToSimplified(const char* pStrTraditional, char* pDstStrSimplified)
{
return TSTransform(pStrTraditional, LCMAP_SIMPLIFIED_CHINESE,pDstStrSimplified);
}

// 简体中文转换成繁体中文(基于GBK编码)
char* SimplifiedToTraditional(const char* pStrSimplified, char* pDstStrTraditional)
{
return TSTransform(pStrSimplified, LCMAP_TRADITIONAL_CHINESE,pDstStrTraditional);
}

AnsiString ConvertJFString(AnsiString sSrc,int mode=0) //mode=0,简体到繁体,1繁体到简体
{
char* pbuf= new char[sSrc.Length()*2];
memset(pbuf,0x00, sSrc.Length()*2);
if(mode==0)
SimplifiedToTraditional(sSrc.c_str(),pbuf);
else
TraditionalToSimplified(sSrc.c_str(),pbuf);
AnsiString s = AnsiString(pbuf);
delete []pbuf;
return s;
}

相关文档
最新文档