C++/CPP: Search and Replace in String

On October 16, 2010, in Coding, CPP, by Dipin Krishna

My CPP function for search and replace in string is given below: string search_replace( string String, string searchString, string replaceString, string::size_type pos = 0) {   while ( (pos = String.find(searchString, pos)) != string::npos ) { String.replace( pos, searchString.size(), replaceString ); pos += replaceString.size(); } return String; } Sample program using it. /* * searchreplace.cpp […]

Tagged with: