bool replace(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
if(start_pos == std::string::npos)
return false;
str.replace(start_pos, from.length(), to);
return true;
}
std::string string("hello $name");
replace(string, "$name", "Somename");
#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;
#include <string>
str1.replace(pos,len,str2);
6 4
3 2 2 2 3 3
Code Example |
---|
Cpp :: time function c++ |
Cpp :: how to round to nearest whole number unity |
Cpp :: sort using lambda c++ |
Cpp :: access part of string in c++ |
Cpp :: change to lowercase character c++ |
Cpp :: use lower bound in pair vector |
Cpp :: latex table landscape |
Cpp :: struct and array in c++ |
Cpp :: rand c++ |
Cpp :: number of lines in c++ files |
Cpp :: how to declare a function in c++ |
Cpp :: c++ typeid |
Cpp :: convert refference to pointer c++ |
Cpp :: segmented sieve of Eratosthenes in cpp |
Cpp :: decltype in c++ |
Cpp :: char ascii c++ |
Cpp :: play audio c++ |
Cpp :: casting c++ |
Cpp :: how to print in cpp |
Cpp :: how to split a string in c++ |
Cpp :: indexing strings in c++ |
Cpp :: for c++ |
Cpp :: how to sort in c++ |
Cpp :: how to check a number in string |
Cpp :: concatenate two vectors c++ |
Cpp :: chudnovsky algorithm c++ |
Cpp :: how to find min of two numbers in c++ |
Cpp :: temperature conversion in c++ |
Cpp :: no template named vector in namespace std |
Cpp :: how to use custom array in c++ |