字符串查找和替换接口
来源:互联网 发布:信用信息数据采集制度 编辑:程序博客网 时间:2024/06/06 01:34
int replace_str(std::string& str, const char * oldpart, const char * newpart)
{
intnReplaced= 0;
std::string::size_type nIdx= 0;
std::string::size_type nOldLen= strlen(oldpart);
if ( 0 == nOldLen )
return 0;
static const char ch = 0x00;
std::string::size_type nNewLen= strlen(newpart);
const char* szRealNew= newpart == 0 ? &ch : newpart;
while ( (nIdx=str.find(oldpart, nIdx)) != std::string::npos )
{
str.replace(str.begin()+nIdx, str.begin()+nIdx+nOldLen, szRealNew);
nReplaced++;
nIdx += nNewLen;
}
return nReplaced;
{
intnReplaced= 0;
std::string::size_type nIdx= 0;
std::string::size_type nOldLen= strlen(oldpart);
if ( 0 == nOldLen )
return 0;
static const char ch = 0x00;
std::string::size_type nNewLen= strlen(newpart);
const char* szRealNew= newpart == 0 ? &ch : newpart;
while ( (nIdx=str.find(oldpart, nIdx)) != std::string::npos )
{
str.replace(str.begin()+nIdx, str.begin()+nIdx+nOldLen, szRealNew);
nReplaced++;
nIdx += nNewLen;
}
return nReplaced;
}
功能: 从str中查找oldpart, 并替换成newpart.
0 0
- 字符串查找和替换接口
- 查找和替换字符串
- 字符串查找和替换
- 字符串查找和替换算法
- C++字符串查找和替换
- vim 查找字符串和字符串替换
- 批处理查找和替换文件指定字符串
- 在LoadRunner中查找和替换字符串
- C# richtextbox查找和替换指定字符串
- 【Loadrunner】字符串查找和替换方法
- 实现字符串的查找和替换
- 在LoadRunner中查找和替换字符串
- vi vim 查找和替换字符串 命令
- js实现字符串的查找和替换
- java字符串查找替换
- 批量查找替换字符串
- Emacs查找替换字符串
- java字符串查找替换
- 【转帖】使用python爬虫抓站的一些技巧总结:进阶篇
- 圖片處理
- 向Android Studio 中导入的Eclipse项目中添加第三方开源库
- GRE写作范文——事物不会一成不变
- my frist app project(第一个app项目)
- 字符串查找和替换接口
- Viewpager完美实现左右循环滑动
- Tomcat 性能优化之APR插件安装
- Android UI
- 进程遍历
- 简单安卓图片自动轮播
- 汉诺塔Python简单实现!
- Android应用安全现状与解决方案(学习资料)
- Windows IOCP