We Recommend

C++ The Core Language C++ The Core Language
C++: The Core Language is for C programmers transitioning to C++. It's designed to get readers up to speed quickly by covering an essential subset of the language. The subset consists of features without which it's just not C++, and a handful of others that make it a reasonably useful language.


Posted By

yuconner on 09/11/06


Tagged

String


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

copyleft


Find and replace one string with another


Published in: C++ 


example: findandreplace( source, "\n", "\n" );

  1. void find_and_replace( string &source, const string find, string replace ) {
  2.  
  3. size_t j;
  4. for ( ; (j = source.find( find )) != string::npos ; ) {
  5. source.replace( j, find.length(), replace );
  6. }
  7. }

Report this snippet 

You need to login to post a comment.