工具类CTools实现字符编码转换和获取当前路径
class CTools
{
public:
CTools(void);
public:
~CTools(void);
public:
static std::string UNICODE_to_UTF8(const CString& unicodeString);
static CString UTF8_to_UNICODE(const std::string& utf8_string);
static std::string ws2s(std::wstring& inputws);
static std::wstring s2ws(const std::string& s); static std::string UNICODE_to_ANSI(const CString& unicodeString);
static CString ANSI_to_UNICODE(const std::string& utf8_string); static std::string GetFullPath(void);
}; CTools::CTools(void)
{
} CTools::~CTools(void)
{
} std::string CTools::UNICODE_to_UTF8(const CString& unicodeString)
{
int stringLength = ::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, (int)wcslen(unicodeString), NULL, , NULL, NULL); char* buffer = new char[stringLength + ];
::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, (int)wcslen(unicodeString), buffer, stringLength, NULL, NULL);
buffer[stringLength] = '\0'; std::string str = buffer; delete[] buffer; return str;
} CString CTools::UTF8_to_UNICODE(const std::string& utf8_string)
{
int length = (int)utf8_string.size(); int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, utf8_string.c_str(), length, NULL, );
wchar_t* wszString = new wchar_t[wcsLen + ];
::MultiByteToWideChar(CP_UTF8, NULL, utf8_string.c_str(), length, wszString, wcsLen);
wszString[wcsLen] = '\0';
CString unicodeText(wszString);
delete[] wszString; return unicodeText;
} std::string CTools::UNICODE_to_ANSI(const CString& unicodeString)
{
int stringLength = ::WideCharToMultiByte(CP_ACP, NULL, unicodeString, (int)wcslen(unicodeString), NULL, , NULL, NULL); char* buffer = new char[stringLength + ];
::WideCharToMultiByte(CP_ACP, NULL, unicodeString, (int)wcslen(unicodeString), buffer, stringLength, NULL, NULL);
buffer[stringLength] = '\0'; std::string str = buffer; delete[] buffer; return str;
} CString CTools::ANSI_to_UNICODE(const std::string& utf8_string)
{
int length = (int)utf8_string.size(); int wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, utf8_string.c_str(), length, NULL, );
wchar_t* wszString = new wchar_t[wcsLen + ];
::MultiByteToWideChar(CP_ACP, NULL, utf8_string.c_str(), length, wszString, wcsLen);
wszString[wcsLen] = '\0';
CString unicodeText(wszString);
delete[] wszString; return unicodeText;
} std::string CTools::ws2s(std::wstring& inputws)
{
return UNICODE_to_UTF8(inputws.c_str());
} std::wstring CTools::s2ws(const std::string& s)
{
CString cstr = UTF8_to_UNICODE(s);
return cstr.GetBuffer(cstr.GetLength());
} std::string CTools::GetFullPath(void)
{
HMODULE h = GetModuleHandle(L"Test.exe");
wchar_t exeFullPath[MAX_PATH]; // MAX_PATH在API中有定义,为128
int len=GetModuleFileName(h,
exeFullPath, //应用程序的全路径存放地址
MAX_PATH);
std::wstring wstrpath = exeFullPath;
std::string strpath = CTools::ws2s(wstrpath);
size_t nPos;
nPos=strpath.rfind('\\');
return strpath.substr(,nPos);
}
工具类CTools实现字符编码转换和获取当前路径的更多相关文章
- Char Tools,方便的字符编码转换小工具
工作关系,常有字符编码转换方面的需要,写了这个小工具 Char Tools是一款方便的字符编码转换小工具,基于.Net Framework 2.0 Winform开发 主要功能 URL编码:URLEn ...
- 编码问题 php字符编码转换类
各种平台和软件打开显示的编码问题,需要使用不同的编码,根据我们不同的需求. php 字符编码转换类,支持ANSI.Unicode.Unicode big endian.UTF-8.UTF-8+Bom ...
- iconv字符编码转换
转自 http://blog.csdn.net/langresser_king/article/details/7459367 iconv(http://www.gnu.org/software/li ...
- php字符编码转换之gb2312转为utf8(转)
在php中字符编码转换我们一般会用到iconv与mb_convert_encoding进行操作,但是mb_convert_encoding在转换性能上比iconv要差很多哦.string iconv ...
- php 字符编码转换函数 iconv mb_convert_encoding比较
在使用PHP处理字符串时,我们经常会碰到字符编码转换的问题,你碰到过iconv转换失败吗? 发现问题时,网上搜了搜,才发现iconv原来有bug ,碰到一些生僻字就会无法转换,当然了配置第二个参数时, ...
- Python—字符编码转换、函数基本操作
字符编码转换 函数 #声明文件编码,格式如下: #-*- coding:utf-8 -*- 注意此处只是声明了文件编码格式,python的默认编码还是unicode 字符编码转换: import sy ...
- day4学python 字符编码转换+元组概念
字符编码转换+元组概念 字符编码转换 #coding:gbk //此处必声明 文件编码(看右下角编码格式) #用来得到python默认编码 import sys print(sys.getdefaul ...
- erlang中字符编码转换(转)
转自:http://www.thinksaas.cn/group/topic/244329/ 功能说明: erlang中对各种语言的编码支持不足,此代码是使用erlang驱动了著名的iconv编码库来 ...
- Qt代码区字符编码转换
在做通讯练习的时候,发现发送给小助手字符乱码,图片如下 本人Qt Creator是UTF-8,需要改成gbk,代码如下 #include<QTextCodec> // 提供字符编码转换 Q ...
随机推荐
- [置顶] 使用mongofiles操作GridFS
使用mongofiles操作GridFS GridFS描述: GridFS,看起来像一种文件系统,其实是一种数据库用法.主要用来在数据库中存储二进制大文件.可以统一用数据库处理数据,而无需借助外部的文 ...
- golang实现udp接入服务器
前端通过udp与接入服务器连接,接入服务器与后端tcp服务器维持tcp连接.目录结构及后端tcp服务器代码同上一篇博客. main.go package main import ( "lot ...
- linux 进程间信号量管理程序之sem_timedwait使用
在开发过程中,有三个独立执行的程序模块,三个模块都对sqlite数据库进行读写操作.sqlite在linux共享性较差,所以须要增加相互排斥信号量解决三个模块訪问数据库该问题. 另外,在增加信号量后, ...
- SQL Server验证的两种方式
1.Windows身份验证:本机连接或者受信的局域网连接(一般在忘记管理员密码或者做系统配置的情况下使用). 2.SQLServer验证:使用用户名.密码验证(推荐使用). 启用方法:以Windows ...
- <META http-equiv=Content-Type content="text/html; charset=gb2312">
META,网页Html语言里Head区重要标签之一 HTTP-EQUIV类似于HTTP的头部协议,它回应给浏览器一些有 用的信息,以帮助正确和精确地显示网页内容.常用的HTTP- EQUIV类型有: ...
- 总线接口与计算机通信(四)USB外部总线(初级认识)
USB简介 USB是英文Universal Serial BUS(通用串行总线)的缩写,是一个外部总线标准,用于规范电脑与外部设备的连接和通讯,是应用在PC领域的接口技术.USB接口支持设备的即插 ...
- iOS中解析json多种方法
我感觉JSON解析,重要的是JSON解析之后对结果的处理JSON解析后是个dictionary,但是字典中有可能包含字典和数组,数组中还可以包含字典.向客户端请求的返回数据解析下面就简单介绍一下JSO ...
- Web性能优化方案
第一章 打开网站慢现状分析 在公司访问部署在IDC机房的VIP网站时会感觉很慢.是什么原因造成的?为了缩短页面的响应时间,改进我们的用户体验,我们需要知道用户的时间花在等待什么东西上. 可以跟踪一下我 ...
- QRadionButton 圆点样式
QRadioButton::indicator { width: 13px; height: 13px;} QRadioButton::indicator::unchecked { ...
- python Unable to find vcvarsall.bat 错误
今天遇到了这个方面的问题,目前找到两种办法.一种是换编译器如mingw,另一种是装vc.第一种方法没成功,现在正在等第二种. 第一种: 首先安装MinGW: 把MinGW的路径添加到环境变量path中 ...