Answers for "find a replace a string in c++"

C++
0

how can I replace a pattern from string in c++

#include <string>
#include <regex>

std::string test = "abc def abc def";
test = std::regex_replace(test, std::regex("def"), "klm"); // replace 'def' -> 'klm'
// test = "abc klm abc klm"
Posted by: Guest on November-11-2021
1

C++ std::string find and replace

#include <string>
#include <regex>

using std::string;

string do_replace( string const & in, string const & from, string const & to )
{
  return std::regex_replace( in, std::regex(from), to );
}

string test = "Remove all spaces";
std::cout << do_replace(test, " ", "") << std::endl;
Posted by: Guest on July-04-2021

Code answers related to "find a replace a string in c++"

Browse Popular Code Answers by Language