首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >C++ 字符串应用--一次性替换所有子字符串

C++ 字符串应用--一次性替换所有子字符串

作者头像
用户7886150
修改2021-02-08 10:00:16
修改2021-02-08 10:00:16
1.1K0
举报
文章被收录于专栏:bit哲学院bit哲学院

参考链接: 用C++程序删除字符串中除字母之外的所有字符 。

// 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; }

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档