1.string字符串删除 字符串中 指定字符

std::string& HTTPRequestHandlerImpl::replace_all_distinct(std::string& str, const std::string& old_value, const std::string& new_value)
{
for (string::size_type pos(); pos != string::npos; pos += new_value.length())
{
if ((pos = str.find(old_value, pos)) != string::npos)
{
str.replace(pos, old_value.length(), new_value);
}
else { break; }
}
return str;
} eg: replace_all_distinct(strring("abcde"), "cd", "dc"); res: abdce

2.string 字符串 转换 utf-8编码

std::string string_To_UTF8(const std::string & str)
{
int nwLen = ::MultiByteToWideChar(CP_ACP, , str.c_str(), -, NULL, ); wchar_t * pwBuf = new wchar_t[nwLen + ];
ZeroMemory(pwBuf, nwLen * + ); ::MultiByteToWideChar(CP_ACP, , str.c_str(), str.length(), pwBuf, nwLen); int nLen = ::WideCharToMultiByte(CP_UTF8, , pwBuf, -, NULL, NULL, NULL, NULL); char * pBuf = new char[nLen + ];
ZeroMemory(pBuf, nLen + ); ::WideCharToMultiByte(CP_UTF8, , pwBuf, nwLen, pBuf, nLen, NULL, NULL); std::string retStr(pBuf); delete []pwBuf;
delete []pBuf; pwBuf = NULL;
pBuf = NULL; return retStr;
} std::string UTF8_To_string(const std::string & str)  
{  
int nwLen = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);  
 
wchar_t * pwBuf = new wchar_t[nwLen + 1];
memset(pwBuf, 0, nwLen * 2 + 2);  
 
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), pwBuf, nwLen);  
 
int nLen = WideCharToMultiByte(CP_ACP, 0, pwBuf, -1, NULL, NULL, NULL, NULL);  
 
char * pBuf = new char[nLen + 1];  
memset(pBuf, 0, nLen + 1);  
 
WideCharToMultiByte(CP_ACP, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);  
 
std::string retStr = pBuf;  
 
delete []pBuf;  
delete []pwBuf;  
 
pBuf = NULL;  
pwBuf = NULL;  
 
return retStr;  

最新文章

  1. 深圳本土web前端经验交流
  2. CSS表格溢出省略号代替及其他标签
  3. 接口性能测试--JMeter
  4. sql中的日期查询
  5. JSTL自定义标签
  6. iOS 验证邮箱手机号格式
  7. MySQL CAST与CONVERT 函数的用法
  8. Chrome插件开发 尝试1
  9. Java 回调函数
  10. Spring MVC 的 研发之路
  11. Myeclipse8.6安装freemarker插件
  12. 读书笔记 effective c++ Item 24 如果函数的所有参数都需要类型转换,将其声明成非成员函数
  13. (NO.00005)iOS实现炸弹人游戏(八):游戏主角(一)
  14. Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)
  15. Python基础-入门之路PYTHON-包 相对导入&绝对导入
  16. 从session中获取当前用户的工具类
  17. 虚拟机极简配置manjaro gnome
  18. 代码编辑器之EditPlus
  19. C# 泛型可能导致的装箱操作陷阱
  20. 排序算法(2)--Insert Sorting--插入排序[2]--binary insertion sort--折半(二分)插入排序

热门文章

  1. 二次开发第N天。。。。。。。。自动分页问题
  2. 通过camera + gallery android上传文件到html
  3. TextView中超链接拦截
  4. python之中国大学爬虫
  5. iOS关于版本更新的问题
  6. XML序列化和反序列化(C#)
  7. ssh密码登陆的原理,密码的公私钥和sshkey的不是一回事
  8. OSX 10.8+下开启Web共享的方法 /转
  9. 常见sql 写法总结
  10. javascript对下拉列表框(select)的操作