Find and replace one string with another


/ Published in: C++
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.