In c++11, you can use std::regex_replace
:
#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"
More Related Contents:
- Replace part of a string with another string
- Check if a string contains a string in C++
- How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?
- C++ string::find complexity
- How to use string.substr() function?
- How to remove all substrings from a string
- What is the most efficient C++ method to split a string based on a particular delimiter similar to split method in python? [closed]
- cannot convert ‘std::string’ to ‘char**’ for argument ‘1’ to ‘__ssize_t getline(char**, size_t*, FILE*)’
- How do I iterate over cin line by line in C++?
- Is a string literal in С++ created in static memory?
- Will std::string always be null-terminated in C++11?
- “\n” or ‘\n’ or std::endl to std::cout? [duplicate]
- Using getline() in C++
- How to reverse an std::string? [duplicate]
- Are there any better methods to do permutation of string?
- Difference between and ?
- Deprecated conversion from string literal to ‘char*’
- How to convert UTF-8 std::string to UTF-16 std::wstring?
- How do I replace all instances of a string with another string?
- C++ Remove punctuation from String
- Why does calling std::string.c_str() on a function that returns a string not work?
- C++ function to count all the words in a string
- Why doesn’t std::string provide implicit conversion to char*?
- Convert double to string C++? [duplicate]
- How can I make the map::find operation case insensitive?
- Parse string containing numbers into integer array
- C++ Passing std::string by reference to function in dll
- Concatenate compile-time strings in a template at compile time?
- C++ most efficient way to convert string to int (faster than atoi)
- How do I include the string header?