UTF-8转化ANSI编码
来源:互联网 发布:南风知我意1七微书包网 编辑:程序博客网 时间:2024/05/19 03:26
说明:
上篇文章介绍了,由ANSI编码格式转化为UTF-8格式,文章链接:http://blog.csdn.net/hong__fang/article/details/42241825
本文主要介绍:由UTF-8格式转化为ANSI编码格式:
一、UTF-8转化ANSI编码程序:
string Utf82Ansi(const char* srcCode){int srcCodeLen=0;//计算接收到待转换字符串的缓冲区所需宽字符数srcCodeLen=MultiByteToWideChar(CP_UTF8,NULL,srcCode,strlen(srcCode),NULL,0);wchar_t* result_t=new wchar_t[srcCodeLen+1];//向result_t缓冲区写入宽字符MultiByteToWideChar(CP_UTF8,NULL,srcCode,strlen(srcCode),result_t,srcCodeLen);result_t[srcCodeLen]='\0';//计算接收到待转换字符串的缓冲区所需字节数srcCodeLen=WideCharToMultiByte(CP_ACP,NULL,result_t,wcslen(result_t),NULL,0,NULL,NULL);char* result=new char[srcCodeLen+1];//向result缓冲区写入字符WideCharToMultiByte(CP_ACP,NULL,result_t,wcslen(result_t),result,srcCodeLen,NULL,NULL);result[srcCodeLen]='\0';string srcAnsiCode="";srcAnsiCode=(string)result;delete result_t;delete result;return srcAnsiCode;}
二、调用形式:
string str = "汉字";string strTemp = Utf82Ansi(str.c_str());
注:这是string类型字符串调用形式,其他类型,可转化为const char* 或 string类型调用。
0 0
- UTF-8转化ANSI编码
- ANSI编码方式转化为UTF-8方式
- ansi、Unicode、Utf-8之间的转化
- ANSI、UTF-8、UNICODE字符串相互转化
- ANSI转化UTF-8的方法
- Ansi编码和UTF-8编码
- 用java实现文本文档的ANSI编码转化为UTF-8
- 字符编码 Unicode UTF-8 UTF-16 UTF-32 ANSI
- ANSI和UTF-8文本编码
- ANSI、UNICODE、UTF-8 文件编码转换
- ASCII、ANSI、UNICODE及UTF-8编码
- UTF-8与ANSI 编码转换
- ANSI与UTF-8编码转换
- 字符编码(ANSI,UTF-8,BINCODE)
- ASCII、ANSI、Unicode及UTF-8编码
- UTF-8与ANSI 编码转换
- ASCII、ANSI、UNICODE及UTF-8编码
- ASCII、ANSI、UNICODE及UTF-8编码
- IOS 设置NSZombieEnabled和MallocStackLogging
- android Instrumentation
- HiPAC高性能规则匹配算法之查找过程
- Android平台下OpenGL初步
- cscope 符号生成
- UTF-8转化ANSI编码
- android中.9图的优势
- Oracle 创建数据库与创建用户的区别
- MFC显示文本文档
- 80386的分段机制、分页机制和物理地址的形成
- 在Sqlite中通过Replace来实现插入和更新
- 判断读入数据文件结尾【从文件读入数据】
- Python vs Ruby
- 购买域名,要注意哪些问题?