C++ str_replace
来源:互联网 发布:电信80端口备案 编辑:程序博客网 时间:2024/05/13 14:08
#include <iostream>#include <string> using namespace std; string& str_replace(const string &search, const string &replace, string &subject); int main(int argc, char *argv[]){ string str; //test basic replace str ="I have a lovely bunch of cocoa nuts"; cout << str << endl; cout << str_replace(" ", " ;", str) << endl; //test removal of spaces str ="I have a lovely bunch of cocoa nuts"; cout << str << endl; cout << str_replace(" ", "", str) << endl; //this test will generate an infinite loop if not done in 1 pass str ="I have a lovely bunch of cocoa nuts"; cout << str << endl; cout << str_replace(" ", " a", str) << endl; return 0;} string& str_replace(const string &search, const string &replace, string &subject){ string buffer; int sealeng = search.length(); int strleng = subject.length(); if (sealeng==0) return subject;//no change for(int i=0, j=0; i<strleng; j=0 ) { while (i+j<strleng && j<sealeng && subject[i+j]==search[j]) j++; if (j==sealeng)//found 'search' { buffer.append(replace); i+=sealeng; } else { buffer.append( &subject[i++], 1); } } subject = buffer; return subject;}
0 0
- str_replace
- C: implementing str_replace to replace all occurrences of substring (zz)
- str_replace() 函数
- str_replace()详解
- str_replace() 函数
- str_replace.php
- C++ str_replace
- str_replace()函数
- PHP函数:str_replace()
- str_replace函数-字符串替换
- PHP str_replace() 函数实例教程
- Sybase中的str_replace问题
- str_replace函数详解
- str_replace函数详解
- PHP str_replace() 函数
- str_replace的简单应用
- PHP str_replace() 函数
- PHP str_replace() 函数
- Caffe使用step by step:使用自己数据对已经训练好的模型进行finetuning
- 架构漫谈(六):软件架构到底是要解决什么问题?
- 实例学习ansible系列(8)常用模块之user/group
- 2016多校训练Contest4: 1010 The All-purpose Zero hdu5773
- Shader特效——实现“Environment Mapping模拟反射和折射”【基于RenderMonkey】
- C++ str_replace
- MongoDB 概念解析
- 深度学习与自然语言处理(8)_斯坦福cs224d RNN,MV-RNN与RNTN
- 利用js获取url当中的参数
- JavaSciript 异步编程
- MVC(mybatis3+spring+springMVC4)框架搭建(一)
- ue4 内存管理 – 实践(废弃)
- jeeplus源码下载,jeeplus共享群,群号581649145
- linux目录结构介绍