C++ 字符串应用--一次性替换所有子字符串
2012-09-06 21:17
176 查看
// StringTest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
//#include <cstddef>
#include "string"
#include "iostream";
using namespace std;
string& ReplaceAll(string& context,const string &from,const string& to)
{
size_t lookHere=0;
size_t foundHere;
while((foundHere=context.find(from,lookHere))!=string::npos)
{
context.replace(foundHere,from.size(),to);
lookHere=foundHere+to.size();
}
return context;
}
int _tmain(int argc, _TCHAR* argv[])
{
//tets
string test="my name is /,/ is a good sutdent";
cout<<ReplaceAll(test,"/","justin")<<endl;
int k=0;
cin>>k;
return 0;
}
//
#include "stdafx.h"
//#include <cstddef>
#include "string"
#include "iostream";
using namespace std;
string& ReplaceAll(string& context,const string &from,const string& to)
{
size_t lookHere=0;
size_t foundHere;
while((foundHere=context.find(from,lookHere))!=string::npos)
{
context.replace(foundHere,from.size(),to);
lookHere=foundHere+to.size();
}
return context;
}
int _tmain(int argc, _TCHAR* argv[])
{
//tets
string test="my name is /,/ is a good sutdent";
cout<<ReplaceAll(test,"/","justin")<<endl;
int k=0;
cin>>k;
return 0;
}
相关文章推荐
- C++字符串高效查找替换
- C++实现字符串替换的两种方法
- C++ 将一个文件里面的相同的一个字符串替换成另一个字符串
- string替换所有指定字符串(C++)
- C++组合应用之strtok字符串分割、数组平分算法、动态数组函数传参
- javascript字符串替换函数如何一次性全部替换掉
- C# 利用正则表达式进行忽略大小写的字符串替换的应用--自定义高亮显示
- c++ 请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
- 【c++】字符串替换:——面试题
- Perl 替换字符串应用
- 2013级C++第17周项目——字符串、指针应用
- C++字符串高效查找替换
- c++的字符串char与string相互转化,以及string的,切割,替换字符,字符串拼接方法(object向c++转型系列教程2)
- C++字符串查找和替换
- C++依次读取文件中的字符串——getline()函数的应用
- Android应用开发之(字符串替换与文本颜色改变方案)
- C++ STL 基础及应用(5) 字符串
- string替换所有指定字符串(C++)
- C++的string替换所有指定字符串(C++)
- C++实现字符串替换