Newer
Older
Tb / Tools / FindAndReplaceString.C
//************************************************
// Author: Federica Lionetto
// Created on: 28/09/2015
//************************************************

/*
Find and replace a string.
*/

// Header guard.
#ifndef __FINDANDREPLACESTRING_C_INCLUDED__
#define __FINDANDREPLACESTRING_C_INCLUDED__

#include "Lib.C"

//************************************************
//
// Declarations.
//

void ReplaceStringInPlace(std::string& subject, const std::string& search, const std::string& replace); 
//************************************************
//
// Definitions.
//

void ReplaceStringInPlace(std::string& subject, const std::string& search, const std::string& replace) {
    size_t pos = 0;
    while((pos = subject.find(search, pos)) != std::string::npos) {
         subject.replace(pos, search.length(), replace);
         pos += replace.length();
    }
    return;
}

#endif