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

繁简转换

[复制链接]
发表于 2004-3-1 23:14:41 | 显示全部楼层 |阅读模式
利用Windows系统自带的简繁体转换的代码,效率较高,能够很好的完成GB2312、GBK到BIG5的转换 主要解答者: taogx 提交人: taogx 感谢: taogx 审核者: flyelf 论坛对应贴子: 查看 A : ! x; l, c( I# `: a4 Z. x
include + P0 _# |( D9 i$ h) e% z
#include
; o6 y" u. V* _2 J5 y; f. P#include 8 o6 E" A6 z; j" w& {
#include
1 E: U1 }+ a3 n4 C* x#include & }0 ]: c# }/ v0 j8 m" Y

+ T2 Z/ j6 P9 q4 w# X( Hchar * j2f(char *s)
1 h) k, [  w) Z7 @/ `{2 A% j! F2 W' H
int n=strlen(s);- G0 S! G9 ^" [) i9 T, O; f
int r=LCMapString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC),LCMAP_TRADITIONAL_CHINESE,s,strlen(s), NULL,0);& q# Y7 Z  o1 t% Y& v/ A
if (!r)
0 Z' T& j+ l, K# f& l( _ return NULL;, z3 C) U( r& q3 }1 V
char *ft=new char[r+1];
: T0 y; f+ K3 u4 h" ~ r=LCMapString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC),LCMAP_TRADITIONAL_CHINESE,s,strlen(s),ft,r+1);//这个api搞掂简体转繁体,下面会打?繁体出来* a/ R4 K7 P' Z$ g# y7 M8 w+ ~* L7 e
if (r) {
. l8 y+ C) Q# ?) E ft[r]=0;
) z9 ]7 _4 ]# X0 C5 P wchar_t *pws=new wchar_t[r+1];. A' M7 z# m) n% K  u: {
int r1=MultiByteToWideChar(936,0,ft,r,pws,r+1);
9 a. V1 X6 Y3 R( j2 f! D( L BOOL f=FALSE;
& o; M" A7 Q9 l1 n# W r1=WideCharToMultiByte(950,0,pws,r1,ft,r+1,"?",&f);//代码页切换搞掂gb->big5
7 U6 x6 f% n/ j$ g ft[r1]=0;5 m# p- I$ `* C- X
delete [] pws;
# P3 w: ^2 H* Z9 c; V! d6 D }6 c4 z" q  t( x' p5 `
strncpy(s,ft strlen(s));
/ v) Y6 U2 L: a delete []ft;
" U$ P  [& R  z" [+ D/ V return s; # Q6 ]2 w* z5 H5 \
} 返回NULL表示失败,如果s为const型,需要提供输出缓冲区,否则你必须释放这个函数返回来的指针的空间。将 strncpy(s,ft,strlen(s)); return s; 这两句的改为缓冲区地址即可。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-15 10:24 , Processed in 0.015707 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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