大侠帮看下转unicode的问题
时间:2010-07-26
来源:互联网
- /*utf8转unicode*/
- int translateUtfToUnicode(char *str,char *res) /*src is source address ,res is destination address*/
- {
- static char buf[32];
- char data[100];
- char temp1; /*save the char*/
- char temp2[3]; /*save the %x of the char*/
- int i=0;
- memset(data,'\0',sizeof(data));
- memset(res,'\0',sizeof(res));
- while(i<strlen(str))/*this code translate utf to unicode*/
- {
- if(!(str[i]&0x080))/*just ascii ,1 utf code*/
- {
- strcat(data,"00");
- temp1=str[i++]&0x07F;
- sprintf(temp2,"%2X",temp1&0x0ff);
- temp2[2]='\0';
- strcat(data,temp2);
- }else if( !( (str[i]&0x0e0)&~0x0c0 ) ){/*just 2 utf code*/
-
- //printf("u 2\n");
- temp1=(str[i]&0x01f)>>2;
- sprintf(temp2,"%2x",temp1&0x0ff);
- temp2[2]='\0';
- strcat(data,temp2);
- temp1=str[i++]<<6;
- temp1|=(str[i++]&0x03f);
- sprintf(temp2,"%2x",temp1&0x0ff);
- temp2[2]='\0';
- strcat(data,temp2);
- }else if( !( (str[i]&0x0f0)&~0x0e0 ) ){/*just 3 utf code*/
- temp1=(str[i++]<<4)&0x0f0;
- temp1|=((str[i]&0x0ff)>>2)&0x00f;
- sprintf(temp2,"%2X",temp1&0x0ff);
- temp2[2]='\0';
- strcat(data,temp2);
-
- temp1=(str[i++]<<6)&0x0c0;
- temp1|=str[i++]&0x03f;
- sprintf(temp2,"%2X",temp1&0x0ff);
- temp2[2]='\0';
- strcat(data,temp2);
- }else{
- break;
- }
- }/*while*/
-
- for(i=0;i<strlen((char*)&data);i++)
- {
- if(i%4==0)
- {
- sprintf(buf,"%c",data[i]);
- strcat(res,"\\u");
- strcat(res,(char*)&buf);
- }else{
- sprintf(buf,"%c",data[i]);
- strcat(res,(char*)&buf);
- }
- }
- }
输出\u9EC4\u9F99\u0039 而不是我想要的\u9ec4\u9f999这种格式?有高手帮忙解决下么
作者: jd808 发布时间: 2010-07-26
帮你顶,有现成的函数吧。
待高人。
待高人。
作者: ecjtubaowp 发布时间: 2010-07-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28