找回密码
 注册
搜索
查看: 4867|回复: 0

繁简转换

[复制链接]
发表于 2004-3-1 23:14:41 | 显示全部楼层 |阅读模式
利用Windows系统自带的简繁体转换的代码,效率较高,能够很好的完成GB2312、GBK到BIG5的转换 主要解答者: taogx 提交人: taogx 感谢: taogx 审核者: flyelf 论坛对应贴子: 查看 A : + o- y% o6 Z( a) B; ]
include ; q9 `% w5 ]& \# U
#include
/ {& i9 W6 F! G- I#include , m$ R8 u% i; s7 o
#include   R: ?% q# G& x9 s2 w7 g3 a8 q
#include 5 m3 k! e5 y4 k

- C$ _$ }7 D" X  S1 Mchar * j2f(char *s)
+ t6 D! W: k# {% {9 h{, M; h* r4 _& \% ^3 i
int n=strlen(s);; e& }, D; j3 ^/ Q& A; r/ Z1 u2 l
int r=LCMapString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC),LCMAP_TRADITIONAL_CHINESE,s,strlen(s), NULL,0);4 U* D  v* }0 P  v4 j
if (!r)0 p+ y* y' _/ R% B# q; A) X
return NULL;
2 y, l8 l" i5 S7 G- y# ^ char *ft=new char[r+1];* \- f0 I  e& @, G* K
r=LCMapString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC),LCMAP_TRADITIONAL_CHINESE,s,strlen(s),ft,r+1);//这个api搞掂简体转繁体,下面会打?繁体出来, y. k( x% T, U8 ?: {: C
if (r) {/ B: t( w1 v% e4 S% s$ B6 t
ft[r]=0;
4 R. L: `" g  _2 A/ T6 ~ wchar_t *pws=new wchar_t[r+1];
1 _' Q: T: E( p int r1=MultiByteToWideChar(936,0,ft,r,pws,r+1);3 n  ?5 G0 T( n' e9 \0 c' K
BOOL f=FALSE;4 a9 m' M; c, J7 o5 N1 y8 p
r1=WideCharToMultiByte(950,0,pws,r1,ft,r+1,"?",&f);//代码页切换搞掂gb->big52 L. ?3 o, ~) V( S$ {* F6 k  t
ft[r1]=0;
2 V6 s9 D& O; q7 G delete [] pws;8 {6 c3 U6 h: R
}0 W( i# \2 O1 i2 x2 I; g
strncpy(s,ft strlen(s));
$ M" F# g8 R) z  W8 F" t" @ delete []ft;! h4 `! D: j2 o- M. n$ w9 o, U
return s; : g0 V4 U' F  z, b* C. u, A
} 返回NULL表示失败,如果s为const型,需要提供输出缓冲区,否则你必须释放这个函数返回来的指针的空间。将 strncpy(s,ft,strlen(s)); return s; 这两句的改为缓冲区地址即可。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|宁德市腾云网络科技有限公司 ( 闽ICP备2022007940号-5|闽公网安备 35092202000206号 )

GMT+8, 2025-11-14 20:02 , Processed in 0.016545 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表